Thanks Fred.
I had a look at the send method. That is exactly what I needed. Also
thanks for not giving the answer in code since I would probably not
have read up on the send method and fully understood it.
But I cannot access the notes attribute in the same way
e.notes << Note.find(:all)
e.notes.size #=> 11
e[‘notes’] #=> nil
Why is it I can access e.name as e[‘name’] but not e.notes as e
[‘notes’]?
Because name is an attribute (ie backed by some column on your table),
but notes isn’t (its an association). The [] and []= methods are
equivalent to read/write_attribute, which as their names suggest are
for playing with attributes.
And is there a work around to access notes only knowing the string
name (“notes”)?
Read up on your ruby (in particular the send method)
Fred
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.