I have a object menu item made available by controller to the corresponding view template. This object has two fields: label and link.
I initiated this object like following in the controller:
// first param is for label and second for link.
menuitem = MenuItem.new("Hello","Say_hello_path")
In the view template I am typing this:
<%= link_to menuitem.label, menuitem.link %>
I expect this to result in: <a href="/say/hello">Hello</a>
but I am getting: <a href="Say_hello_path">Hello</a>
What am I doing wrong? Is there a better way to achieve the expected result?
The second item in MenuItem.new(“Hello”,”Say_hello_path”) is a string. When you call <%= link_to menuitem.label, menuitem.link %>, it is just putting the string.
You can try the following
Or, you can try to eval the string in the link_to (you’ll need to fix the case on the method name).
Eval isn’t usually recommended, but may be what you need in this case.