Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authorize_resource with multiple classes(Models) ? #18

Closed
rajesh2210 opened this issue Mar 12, 2014 · 1 comment
Closed

authorize_resource with multiple classes(Models) ? #18

rajesh2210 opened this issue Mar 12, 2014 · 1 comment

Comments

@rajesh2210
Copy link

Rails 4 + Cancan

ability.rb
if user.is_sys_admin?
can :manage, [MdmArea, MdmCity, MdmCountry, MdmState] #Model Array
end

mdm_controller.rb

authorize_resource ['MdmCountry', 'MdmState', 'MdmCity', 'MdmArea'] # Not working

Please solve this ? or any solution
Thanks

@bryanrite
Copy link
Member

Hello @rajesh2210

Your line in ability is fine, you can specify an ability on multiple models.

I don't believe you can authorize multiple models in a single authorize_resource call.

Essentially you are saying that the user has to be have ability on all 4 objects to authorize the controller action. This indicates to me that there is actually a logical parent object (that may not exist) that is composed of the 4 models above, maybe something like MdmAddress. What you probably want to do is authorize on MdmAddress and then conditionally allow the user to manage parts of the Address using can? :read, MdmState in the view or strong_parameters permit array.

We are currently enhancing can? to allow you to check multiple models in #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants