Created
July 20, 2013 16:17
-
-
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?
This file contains hidden or 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
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