[Rails] 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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home