Example:
User A (id=10) has created a photo resource
photo: (id: 1 user_id = 10, url: "http://...")
Now, if User B (id=20) go to this url: /photos/1/edit
it can edit photo of user A!!!
Rails+Devise provides something for this by default? It seems it's a very common issue
I just need to allow that any user can edit/delete ONLY resource it has created (where current_user == resource.user)
Using: Rails 4, Devise
Update:
I think CanCan it's something too advanced. I don't need roles or restrict some actions to certain users
The simplest would be to to modify routes.rb.
Assign photos to live in the current_user path.
For example,
If CanCan is too advanced, you should loon into checking the id of the accessor in the controller using...
...or something like that
I captured the exception from within a before_filter action:
Hope this helps someone. I'm using Rails 4 and Ruby 2.
Check this railscasts,
http://railscasts.com/episodes/192-authorization-with-cancan
Complications you will run into,
When you want cancan authorization on User Model that Devise gem is using for authentication
When you want to store your Roles in the Database
When you want to assign Permissions to the Roles as an Admin from the webUI
and more ..
Please comment if you want any of those features, I will be happy to help, because I recently did them with great help from others and its always amazing to pass it on.
A sample Ability for your resources can be like as follows,
In your PhotosController:
cancan is difficult and complicate i have coding
is_onwer
method it's very simple, easyhttps://gist.github.com/x1wins/0d3f0058270cef37b2d3f25a56a3745d