rolify: Method missing with Rails4.0rc + rolify

So using rolify 3.3.0.rc4 c8218ad. I was earlier running on 3.2 and decided to update the gem. Now I’m seeing;

rails4.0.0/gems/activerecord-4.0.0.rc1/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `scopify' for #<Class:0x007f933d2d0938> (NameError)

Heres Role.rb

class Role < ActiveRecord::Base

  has_and_belongs_to_many :users, :join_table => :users_roles
  belongs_to :resource, :polymorphic => true

  scopify
end

Extending Role with Rolify seems to help though.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 24 (11 by maintainers)

Most upvoted comments

I get the same issue with the react-rails gem but changing the order in the gemfile fixed the issue

If I read the The Rails Initialization Process doc correctly, Rails first use bundler in config/boot.rb to setup load paths and then require railties and engines in application.rb.

  # Rails::Application is responsible for executing all railties and engines
  # initializers. It also executes some bootstrap initializers (check
  # Rails::Application::Bootstrap) and finishing initializers, after all the others
  # are executed (check Rails::Application::Finisher).

So basically, you should just need to add gem "rolify" in your Gemfile and the magic happens. I don’t know what corner case you hit that prevents this normal behaviour. Add this to your application.rb to force the railtie to load:

require 'rolify/railtie'