Wednesday, January 27, 2016

undefined method `want=' for nil:NilClass (NoMethodError)

In Rails 4.2, you can define your own application specific custom variables in development.rb, test.rb and so on. If you define this:

  config.x.whatever.value.want = 42

It throws the error : undefined method `want=' for nil:NilClass (NoMethodError)

It seems to work only for two levels, so, this will work:

  config.x.whatever.value = 42

You can access the value like this:

Rails.configuration.x.whatever.value

You need to define the custom values by using 'config.x'.