Alexey Petrushin
2011-Aug-19 23:18 UTC
ActiveModel, run after & before callbacks separately?
Hello, is there a way to run ActiveModel callbacks separately? Usually You do it with block (see sample below), but I have composite model (for MongoDB, model with embedded models inside) and callbacks should be run on all models. In other words - the :before_create should be run on all models, after it models will be created and after it the :after_create also should be fired on every documents. Actually it''s possible use chain of nested blocks to do it, but in case of ~500 nested models the stack trace will be about the same size, and it''s complicated, so I don''t want to do it. Here''s the code: def create run_callbacks :create do # Your create action methods here end end What I need is something like this: def create run_callbacks :before_create # Your create action methods here run_callbacks :after_create end Thanks. P.S. Also if You need to save any plain ruby object to MongoDB (also composite and nested) try this https://github.com/alexeypetrushin/mongo_db -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alexey Petrushin
2011-Aug-21 14:20 UTC
Re: ActiveModel, run after & before callbacks separately?
Hm the source code in ActiveSupport Callbacks is auto-generated and very complicated (probably to optimize performance). So, I created standalone version of callbacks, they are much simpler (but probably not so fast as ActiveSupport Callbacks) https://github.com/alexeypetrushin/ruby_ext/blob/master/spec/more/callbacks_spec.rb -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.