Forum: Ruby on Rails Child calls

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D64d1a2ad3538a5f089839e37e888948?d=identicon&s=25 james (Guest)
on 2006-05-04 18:23
If I use <%= parent.name %> and or <%= parent.child.name %> then i get
the correct record.

BUT if say <% nameholder = "parent.child.name" %>
<%= nameholder %> it just prints parent.child.name.

How do I get ruby to recognize nameholder as object?

Thanks,

James
6ec1e89eef5ce09fbfa56be5b6dd17b5?d=identicon&s=25 Adam Bloom (admanb)
on 2006-05-04 18:24
Don't quote parent.child.name.

<% nameholder = parent.child.name %>
D64d1a2ad3538a5f089839e37e888948?d=identicon&s=25 james (Guest)
on 2006-05-04 18:32
Adam Bloom wrote:
> Don't quote parent.child.name.
>
> <% nameholder = parent.child.name %>


Thanks for the quick response.

<% nameholder = "parent.child.name" %> The quotes are actually from some
other logic where I am parsing a string in order to create the correct
parent.child.name... in other words Im creating it dynamically but how
do I change it back to a command from a string.

Obviously Im a newbie, but I appreciate your help/patience.

James
6ec1e89eef5ce09fbfa56be5b6dd17b5?d=identicon&s=25 Adam Bloom (admanb)
on 2006-05-04 18:44
I don't think that's possible. However, I KNOW it's possible to
dynamically create code. My suggestion is you post your code block that
creates that string, and wait for someone with more Ruby knowledge than
I to help you convert it into working Ruby.

-Adam
6cf8286fcab5843f468d62f5e6fb22de?d=identicon&s=25 Henry Turner (Guest)
on 2006-05-04 19:03
(Received via mailing list)
You're trying to execute a method named by the result of
parent.child.name?

You could try..

<% nameholder = eval(parent.child.name.to_s) %>

-henry
D64d1a2ad3538a5f089839e37e888948?d=identicon&s=25 james (Guest)
on 2006-05-04 19:09
Henry Turner wrote:
> You're trying to execute a method named by the result of
> parent.child.name?
>
> You could try..
>
> <% nameholder = eval(parent.child.name.to_s) %>
>
> -henry

I love you.

Thanks That was it!
This topic is locked and can not be replied to.