Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def your_after_save_func
- YourModel.without_callbacks(:your_after_save_func) do
- Your updates/changes
- end
- end
- send(name.to_s + '=', value)
- def before_save
- @attempted_save_level ||= 0
- @attempted_save_level += 1
- end
- def after_save
- if (@attempted_save_level == 1)
- #fill in logic here
- save #fires before_save, incrementing save_level to 2, then after_save, which returns without taking action
- #fill in logic here
- end
- @attempted_save_level -= 1 # reset the "prevent infinite recursion" flag
- end
- Class Foo << ActiveRecord::Base
- after_save :init_bar_attr, :if => "bar_attr.nil?" # just make sure this is false after the callback runs
- def init_bar_attr
- self.bar_attr = "my id is: #{self.id}"
- # careful now, let's save only if we're sure the triggering condition will fail
- self.save if bar_attr
- end
Add Comment
Please, Sign In to add comment