KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
UPDATE I wrongly checked the edgerails guide instead of the currently correct Rails 3 guide (which has no mention of after_initialize). Not sure why the edgerails guide is "incorrect" though - I thought edgerails guide was supposed to be the latest up-to-date guide? I'm leaving this question as-is just in case someone comes looking for the same "problem". Macro-style call to after_initialize is the way to go. Should after_initialize be used as method or macro-style call ? This works, but gives a deprecation warning: def after_initialize logger.info "Called after_initialize" end DEPRECATION WARNING: Base#after_initialize has been deprecated, please use Base.after_initialize :method instead. This works, and there is no warning: after_initialize :do_this_after_initialize def do_this_after_initialize logger.info "Called after_initialize" end But the Active Record Validations and Callbacks Guide in 10.4 after_initialize and after_find says: ...If you try to register after_initialize or after_find using macro-style class methods, they will just be ignored. This behaviour is due to performance reasons, since after_initialize and after_find will both be called for each record found in the database, significantly slowing down the queries... So that means that the macro-style usage is inefficient versus the method-style way? (I guess the guide is wrong, 'cos code is king :D) Another Update A commit here from January 28
Tags (comma-separated)
Save Edits
Cancel