Fail with rolify/cancan option. #17

stevenkolstad opened this Issue Apr 20, 2012 · 10 comments


None yet
8 participants
    gsub    app/models/user.rb
    gsub    app/models/user.rb
    gsub    app/models/user.rb
     run    rails generate devise:views from "."
/app/models/user.rb:2:in `<class:User>': undefined local variable or method `rolify' for User:Class (NameError)
from /app/models/user.rb:1:in `<top (required)>'

dhf0820 commented May 1, 2012

rolify need to be after the includ mongoid. But this error stops the completion of the generator. I figured I could specify no cancan and rolify getting it to work. It does generate but then fails on invitation_token not found. I am about to give up as there seems to be issues with this generator.

l4u commented May 7, 2012

@dhf0820 for the fails on invitation_token,
It works for me when the User Model has these field:


DanielKehoe commented May 13, 2012

@dhf0820 and @l4u thanks for your patience and understanding, I can't test all possible combinations of the preferences, so I appreciate that you brought this error to my attention. I've updated the application template to correct the error. Please test and let me know if the issue is resolved.

-- Daniel

ryudice commented May 25, 2012

It doesnt work for me still

Yes, it also doesn’t work for me. I was able to add the controller after I moved rolify below include Mongoid::Document as suggested above, but can I somehow continue the template after that?

When I answer n to the CanCan & Rolify question, it works for me. I don’t expect it to be too difficult to incorporate those after the fact.

The problem is that Rolify 3.1 (which is required by the template) has an issue with Mongoid, causing the generation process to fail. The issue has been fixed in Rolify 3.2.0.beta4.

Until Rolify is released, an acceptable workaround could be to prepend the call to rolify in the user model with include Mongoid::Document, as you can see here. I think it should be easy to do this using gsub_file in the AddUser recipe, right after the call to generate 'rolify:role Role User mongoid'

This solved the issue for me


DanielKehoe commented Jun 11, 2012

I've updated rails_apps_composer and the application templates to incorporate your suggestions. Please test and let me know if the issue is resolved. Thanks for your help and patience!

Yes, it works for me now, thanks!


DanielKehoe commented Jun 12, 2012

@backspace Thanks for the feedback. I'll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment