Rails 4.2.3 Serialized Model Not Updating Attribute
I am running Rails 4.2.3. I have a model Volunteer
with a serialized attribute participated
. After the object is created, I cannot update the attribute participated
:
> @volunteer = Volunteer.new( participated: {'citizenship' => '', 'daca' => ''} )
=> #<Volunteer id: 1, participated: {'citizenship' => '', 'daca' => ''}>
> @volunteer.participated['citizenship'] = 'test'
=> {'citizenship' => 'test', 'daca' => ''}
> @volunteer
=> #<Volunteer id: 1, participated: {'citizenship' => 'test', 'daca' => ''}>
> @volunteer.changed?
=> true
> @volunteer.save
=> true
> Volunteer.last
=> #<Volunteer id: 1, participated: {'citizenship' => '', 'daca' => ''}>
As you can see, the database is not being updated. I originally ran rails 4.2.0. At that time he changed?
did not even return true
- in this case he returned false
. After doing some searching, this pull request on GitHub made me suspect that the problem might be a Rails bug. The update for rails 4.2.3 fixed the issues with changed?
, but the database is still not updated.
Any suggestions would be greatly appreciated! I still dive into it ever since.
For what it's worth:
class Volunteer < ActiveRecord::Base
serialize :participated
end
class CreateVolunteers < ActiveRecord::Migration
def change
create_table :volunteers do |t|
t.text :participated
t.timestamps null: false
end
end
end
source to share
No one has answered this question yet
Check out similar questions: