I'm not sure that this can be achieved, but here it goes ... :)
Suppose two models, model Pageand model Field. A Page has_many :fieldsand model Fieldhave two attributes::name, :value
What I want to achieve is in the model Pagefor dynamically defining instance methods for each Field#namereturning one Field#value.
So, if there was a field named "foobar" on my page, I would dynamically create a method like this:
def foobar
fields.find_by_name("foobar").value
end
Can this be achieved? If yes, please help?
To rubists ...
source
share