When I generated a scaffold for a model class named menuitem, it generates a class file for menuitem, but in the database creates menu_item and refers to the class in the views and controller as menu_item. This may be causing me quite a headache as im genereating a newsted show link, but its failing telling me missing method. The rake routes tells me the show route should be menu_menu_item, but when i do:
<td><%= link_to 'Show', menu_menu_item(@menu) %></td>
it doesnt work.
Is that because of the funky two word class name?
You must have generated either menu_item
or menuItem
or MenuItem
. It doesn't know where one word stops and another starts unless you tell it.
Also, for your link_to
s, you just need to append _path
:
<td><%= link_to 'Show', menu_menu_item_path(@menu) %></td>
Well, actually, that looks a little wrong to me. That looks like you're trying to go to a single item, which I think will require you to specify both the menu and the item:
<td><%= link_to 'Show', menu_menu_item_path(@menu, @menu_item) %></td>
And to all the menu items in a menu:
<td><%= link_to 'Show', menu_menu_items_path(@menu) %></td>
Pluralizer显示您可以根据Rails的约定来命名事物。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.