Using Rails serialize to save hash to database

Viewed 101296

I'm try to save a hash mapping ids to a number of attempts in my rails app. My migration to the database to accommodate this new column:

class AddMultiWrongToUser < ActiveRecord::Migration
  def self.up
    add_column :users, :multi_wrong, :string
  end

  def self.down
    remove_column :users, :multi_wrong
  end
end

In my model I have:

class User < ActiveRecord::Base 
 serialize :multi_wrong, Hash
end

But when I use the rails console to test this by doing:

user = User.create()
user.multi_wrong = {"test"=>"123"}
user.save

The output is false. What's going wrong here?

3 Answers
Related