Search code examples
ruby-on-railsrubyruby-on-rails-3rubygemsnomethoderror

Getters/settings not working when using the rails-setting gem - method missing error


I'm using the rails-settings gem: https://github.com/huacnlee/rails-settings-cached

The getter/setter method are not working.

I've added the following line to my user model as directed:

include RailsSettings::Extend

I've also tried adding it to role.rb (as I am using rolify gem)

However is am still getting the following error message:

NoMethodError: undefined method `settings' for #<User:0x007f8dd017a560>
    from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353@accufly/gems/activemodel-3.2.13/lib/active_model/attribute_methods.rb:407:in `method_missing'
    from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353@accufly/gems/activerecord-3.2.13/lib/active_record/attribute_methods.rb:149:in `method_missing'
    from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353@accufly/gems/rolify-3.2.0/lib/rolify/role.rb:73:in `method_missing'
    from (irb):24
    from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353@accufly/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353@accufly/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /Users/jamieturner/.rvm/gems/ruby-2.0.0-p353@accufly/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

When I run:

user = User.find(2)
user.settings.color = :red

Can anyone see what the issue is?


Solution

  • Ok, I've solved the issue.

    I had not restarted the console session.....restarting it got it working!