As mentioned previously, we did a lot of work when setting up user accounts in our system but nothing to actually connect, or even restrict access to, polls and user accounts. Thinking back to how we've set up other associations, there are a couple of steps that we have to implement before all of our polls are correctly linked to users. They are as follows:
- We need to link our tables by creating a migration that adds user_id to our polls table.
- We then need to modify the code in our schemas to represent the addition of the association.
- We need to modify all of the creation code in the context to set the poll's user_id to the appropriate user.
- Finally, we need to modify all of the delete and update code to only allow those functions to happen if the current user is the owner of that poll.