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

Hash conditions containing symbols problem #65

Closed
Silex opened this issue May 27, 2014 · 4 comments
Closed

Hash conditions containing symbols problem #65

Silex opened this issue May 27, 2014 · 4 comments
Assignees

Comments

@Silex
Copy link

Silex commented May 27, 2014

Hello,

I found this blog post that explain the problem I'm having:

http://www.tigraine.at/2014/03/13/cancan-beware-of-symbol-conditions

Basically, if you look at the following rules:

can :manage, Item, user: { role: :admin }  #1
can :manage, Item, user: { role: 'admin' } #2

With both rules Item.accessible_by(current_ability) will return the correct results. But only the 2nd rule will work with can? :manage, Item.accessible_by(current_ability).first

This is because the symbols are not translated to a string the usual way rails does.

Not sure if really a bug or a not.

[EDIT] I believe this is a bug, just because of the unexpected behavior.

@Tigraine
Copy link

I believe this to be a bug, at least it's something new users will surely trip over and I can't think of a good and valid use case for wanting that behavior (since it does work differently on ActiveRecord queries)

@vendethiel
Copy link

That's how ActiveRecord behaves.

User.where(role: :admin)

@bryanrite
Copy link
Member

I agree, this should probably be fixed.

@freemanoid
Copy link

I think this is not a bug. There is a similar issue in Squeel gem.
There is a note in rails docs:

The values cannot be symbols. For example, you cannot do Client.where(status: :active).

Thus it's not a bug, actually it's just a trick that you can sometimes use symbols as values.
Related issue: activerecord-hackery/squeel#67

@Senjai Senjai self-assigned this Jun 13, 2015
@Senjai Senjai closed this as completed Aug 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants