My model has a serialize :settings field. It is also validated by some custom validation. I now want to initialize that field when an 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)
Asked
Active
Viewed 525 times
1
medihack
- 16,045
- 21
- 90
- 134
-
Interesting - what happens if you try to initialize it with something like a Hash or an Array? – Cory Dec 05 '10 at 22:05
-
Cory is right to ask that. also, what happens if you do this YAML::dump(Settings.new) – ffoeg Jan 06 '11 at 06:28
1 Answers
0
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
Community
- 1
- 1
Benjamin Tan Wei Hao
- 9,621
- 3
- 30
- 56