ruby on rails - Call a method on a variable where the method name is in another variable -


<% @labels.each |label| %>     <input type="text" name="<%=label.name%>" value="<%=@car.(label.related_to) %>" class="big-font" style="width: <%=label.width%>px; top: <%=label.y_coor%>px; left: <%=label.x_coor%>px;" />  <% end %> 

hello guys, i'm new rails should easy question answer.

the issue here: <%=@car.(label.related_to) %>.

label.related_to holds string "make". i'm trying pretty much: @car.make

any idea guys?

thanks, alain

use send send message object:

@car.send(label.related_to) 

if there chance of label.related_to not being valid method object, you'll want prepared catch nomethoderror


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -