I have a STI class tree. I want to set some default values (calculated
values so I can’t set it in the database as defaults) on every created
instance regardless of what subclass is actually instantiated. So I
figured adding a after_create callback in the top class in the hierarchy
should do the trick. It seems it doesn’t get called
Code:
class SuperClass < ActiveRecord::Base
…
after_create :set_defaults
…
private
def set_defaults
puts “Setting defaults #{id}”
… set values …
save()
end
end
How does this article relate to the subject? I see you mention STI there
but it’s in the context of Reloadable classes.
Quick tips:
don’t override self.inherited
Why? Is Rails doing something there as well? How do I do if I want to do
something like generate methods based on my own conventions when
subclassed (in this particular class hierarchy)?
put validations/callbacks ABOVE associations (especially in Rails 1.0)
Okay, I’ll try that.
Thanks
/Marcus
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.