'ActiveModel - `undefined method `write_from_user' for nil:NilClass`
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?
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
