Skip to content

Instantly share code, notes, and snippets.

@pacoguzman
Created September 12, 2009 15:12
Show Gist options
  • Save pacoguzman/185873 to your computer and use it in GitHub Desktop.
Save pacoguzman/185873 to your computer and use it in GitHub Desktop.
class ActionDuck
attr_accessor :errors
def initialize(h)
h ||= {}
h.each { |k,v| send("#{k}=", v) }
self.errors = ActiveRecord::Errors.new(self)
end
# These make a class quack like an AR::Base
class << self
def self_and_descendants_from_active_record
[self]
end
def human_name
self.name.humanize
end
def human_attribute_name(attribute_key_name, options = {})
attribute_key_name.to_s.humanize
end
end
# These make an instance quack like an AR::Base
def new_record?
true
end
def id
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment