开发者

Where to initialize a serialization field that is validated?

开发者 https://www.devze.com 2023-01-28 04:57 出处:网络
My model has a serialize :settings field. It is also validated by some custom validation. I now want to initialize that field when a开发者_StackOverflow社区n object is created (self.settings = Setting

My model has a serialize :settings field. It is also validated by some custom validation. I now want to initialize that field when a开发者_StackOverflow社区n object is created (self.settings = Settings.new). So I tried to it in an after_initialization callback. But that gives me Can't convert Settings into String. The same happens when using the before_validation callback. But when assigning the Setting.new manually after the object was built there is no problem at all. Why can't I use those callbacks to set serialization fields? (Rails3)


Make sure that your :settings field is in fact of type :text rather than :string. It might help you to check out : something similar here

0

精彩评论

暂无评论...
验证码 换一张
取 消