ActiveModel - `undefined method `write_from_user' for nil:NilClass`

905 Views Asked by At

I have simple class:

class Settings
  include ActiveModel::Model, ActiveModel::Attributes

  attribute :display_raw_results, :boolean, default: false
end

When I try to initialize it with empty hash it works.

Settings.new
# or
Settings.new({})

But if I pass a value in this hash it fails with expection

Settings.new(display_raw_results: true) 
# results in:  undefined method `write_from_user' for nil:NilClass

What I'm doing wrong?

1

There are 1 best solutions below

1
Aleksandr K. On BEST ANSWER

Turns out the problem was in one line include. After including modules separately it works as expected.

class Settings
  include ActiveModel::Model
  include ActiveModel::Attributes

  attribute :display_raw_results, :boolean, default: false
end