Skip to content

Instantly share code, notes, and snippets.

@biagidp
Created December 21, 2011 20:23
Show Gist options
  • Save biagidp/1507541 to your computer and use it in GitHub Desktop.
Save biagidp/1507541 to your computer and use it in GitHub Desktop.
class_eval implementation
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