Answer the question
In order to leave comments, you need to log in
Why, after redefining the receipt of a field from the model, its change does not work?
Hello.
There is a model. It has an options field, of type json. In the database, this field can be null.
I want that in rails, if in the base this field is null, then I would still return an empty Hash.
I wrote this method (in the model)
def options
self[:options] || {}
end
instance.options[:some_key] = some_value
instance.options = {some_key: some_value}
Answer the question
In order to leave comments, you need to log in
can be written like this
def options
self[:options] ||= {}
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question