Using Rails serialize to save hash to database
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: 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 In my model I have: class User 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? 回答1: The column type is wrong. You should use Text instead of String. Therefore, your migration should be: def self . up add_column : users , : multi_wrong , : text