I have an existing user which has a serialized field and I want to be able to add recent messages to the array / serialized field.
class User < ActiveReco
It's because the first time you try to push an item to your recent_messages
, there's no array to push the item into (the field is nil
by default). So you must create the array before you can push to it
@user = current_user
if @user.recent_messages.nil?
@user.recent_messages = [params[:message]]
else
@user.recent_messages << params[:message]
end
@user.save