I’m new to rails and I am using devise for authentication.
I have a route called /users/5/events/1/add_images to which the current_user should only have access if @user == current_user. What’s the best way to set this permission? Should this be done on the controller level?
Any help would be appreciated! Thanks!
Yes, it should be done at the controller level.
You can use the
cancangem for handling authorization.https://github.com/ryanb/cancan
http://railscasts.com/episodes/192-authorization-with-cancan
Roughly, you have to define the ability:
In the events_controller, add a before_filter
That’s the general idea, read the doc for the rest.