Created
December 21, 2011 20:23
-
-
Save biagidp/1507541 to your computer and use it in GitHub Desktop.
class_eval implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
module SaveAsDraft | |
ActiveRecord::Base.class_eval do | |
alias_method :save_without_draft, :save | |
def save_with_draft | |
if self.has_attribute?(:record_status) and self.record_status == "Draft" | |
save_without_draft(:validate => false) | |
else | |
save_without_draft | |
end | |
end | |
alias_method :save, :save_with_draft | |
end | |
end | |
ActiveRecord::Base.send(:extend, SaveAsDraft) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment