ryanb / cancan

Authorization Gem for Ruby on Rails.
MIT License
6.27k stars 783 forks source link

can :manage, Comment, :user_id => @usr.id not working, but :user => {:id => @usr.id} works #502

Closed swobspace closed 12 years ago

swobspace commented 12 years ago

The following definition didn't give the user @usr any rights:

can :manage, Comment, :user_id => @usr.id

But if I use the following definition

can :manage, Comment, :user => { :id => @usr.id }

all works as expected. As the wiki page "Defining Abilities" mentioned, both should be equivalent.

I'm using Rails 3.1.1, cancan 1.6.7 and ruby 1.8.7.

wob

yangman-tutu commented 12 years ago

what is its role? i use it in my app, had an exception: RuntimeError in RailsAdmin::MainController#new

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

zliang-min commented 12 years ago

I've just tested it in a new Rails 3.1.1 application with cancan 1.6.7 and ruby 1.8.7, and didn't have this problem. Are you still having this problem? If you are, would you please offer more details?

andhapp commented 12 years ago

@swobspace: I am going to close this issue for now. If you still have this issue, please comment here and it'll be reopened for further discussion/investigation.

yangman-tutu commented 12 years ago

i have fixed it,can i use like this :manage, Comment, :user_id => user.id cheerly!

swobspace commented 12 years ago

@Gimi @andhapp: I can't test it at the moment, I switched to Rails 3.2 with the patch from jpascal #577 to use rails 3.2 mass assignment stuff., so I'm not on the master branch.