No, this is not possible when using the ActiveRecord serialization feature because the serialization/deserialization must be controller by ActiveRecord and update performs a direct SQL update call on the database.
Some non-relational database (such as MongoDB) offers this feature because they are designed in order to do so. PostgreSQL provides a Hash extension you can install that would allow you to perform direct operations on the serialized field.
In all the other cases, you could potentially update the field directly, but I don't encourage you to do so. There is a potential risk to write corrupted data.
Instead, I suggest you to create a custom method that performs both the push and save. In any case, this is a good idea because you are exposing a custom API outside the model instead of coupling your model to the ActiveRecord architecture.
class Impression < ActiveRecord::Base
serialize :actions, Array
def add_action(action)
self.actions << action
self.save
end
end
The you can use
impression = ...
impression.add_action "new_value"
ruby-on-rails-4tag because the.updatesyntax is different for earlier versions (I think).updatein Rails 4 is the same ofupdate_attributesbefore, but I agree the tags makes sense here. Sorry for the change.