User Functionality
Explore how to add user functionality in a Ruby on Rails app by associating created links with users, restricting access with Devise, and controlling view permissions. Understand how to modify controllers and views to ensure only signed-in users can create, edit, or delete links tied to their accounts.
We'll cover the following...
We'll cover the following...
Now, you will need to add some user-based functionality. You will do the following:
- Configure actions so new links that are created are associated with the user that creates them. You will have noticed that you were not able to create new links after creating an association between
UserandLink. - Edit
links_controller.rbso a non-user only has access to theindexandshowviews. - Configure
app/views/links/index.html.erbso a user cannot access theEditandDestroypaths for links created by a different user.
Configure actions
You need to configure some actions in your app/controller/links_controller.rb file to assign user_id to the link that the user creates.
In app/controller/links_controller.rb make the changes to the new action:
def new
@link = current_user.links.build
end
@link ...