Skip to content

Instantly share code, notes, and snippets.

@blischalk
Created July 20, 2013 16:17
Show Gist options
  • Save blischalk/6045591 to your computer and use it in GitHub Desktop.
Save blischalk/6045591 to your computer and use it in GitHub Desktop.
Trying to use a decorator with a form object but valid? only seems to return errors for outer level instance. What is the best way to accomplish decoration of FormObjects?
class MyDecorator
attr_accessor :age
validates_presence_of :age
def initialize(subject)
@subject = subject
end
def method_missing(name, *args)
@subject.send(name, *args)
end
end
class MyBaseForm
attr_accessor :name
validates_presence_of :name
end
test = MyDecorator.new(MyBaseForm.new)
test.valid?
test.errors # Only has age error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment