Can an ActiveRecord before_save filter halt the save without halting the transaction?
Posted
by
Michael Boutros
on Stack Overflow
See other posts from Stack Overflow
or by Michael Boutros
Published on 2012-06-28T14:54:19Z
Indexed on
2012/06/28
15:16 UTC
Read the original article
Hit count: 167
ruby-on-rails
Is there any way for a before_save filter to halt the entire save without halting the transaction? What I'm trying to do is have a "sample" version of my model that the user can interact with and save but the changes themselves are never actually saved. The following will halt the transaction and (naturally) return false when I call @model.update_attributes:
before_filter :ignore_changes_if_sample
def ignore_changes_if_sample
if self.sample?
return false
end
end
Thanks!
© Stack Overflow or respective owner