-
-
Notifications
You must be signed in to change notification settings - Fork 630
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
Support ActiveRecord 4.x enums #196
Conversation
I've been bumping into this issue as well. Thanks for the fix! |
Hey, guys! What about this PR? I think it's pretty important patch because it's not possible to use cancancan with enums right now. |
Would love to see more support for enums in CanCanCan. In the meantime, this is what I have been doing: can :read, ::Media, :published? => true |
@nelsonwittwer, suppose that your approach will not work with |
👍 would love to see this get merged |
@jwg2s @markpmitchell I rebased your changes and pushed them to master. Thank you for your contribution! Sorry it took a while to get around to. |
👍 |
Hey-ho! Great news! ❤️ |
Thanks! Mark Mitchell On Oct 7, 2015, at 8:19 PM, Richard Wilson notifications@github.com wrote: @jwg2s https://github.com/jwg2s @markpmitchell — |
Fixes Issue #102
ActiveRecord queries for records with enums are by integer value, not by symbol. As CanCan uses the same query syntax, the way to specify a condition based on enum values is like so:
can :read, Shape, color: Shape.colors[:blue]
While CanCan already generated the correct SQL queries for accessible_by, checks against individual objects did not work because the value of an enum attribute is a String. Therefore, the ActiveRecord 4 adapter must special case matches_condition? to convert the String to the appropriate integer before comparing against the value provided in the condition.