November 2011
1 post
Model default values
When looking for the best way to make default values, I’ve found that you shouldn’t rely on the DB for these. So in order to integrate these on your Model, I usually follow the next best practive:
class User after_initialize :init def init self.number ||= 0.0 end end
This way it will initialize to 0.0 if the value is nil