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:
当我为名为menuitem的模型类生成一个脚手架时,它会为menuitem生成一个类文件,但是在数据库中创建menu_item并将视图和控制器中的类称为menu_item。这可能会让我非常头疼,因为我正在创建一个新闻节目链接,但它没有告诉我丢失的方法。 rake路线告诉我show show应该是menu_menu_item,但是当我这样做时:
<td><%= link_to 'Show', menu_menu_item(@menu) %></td>
it doesnt work.
它不起作用。
Is that because of the funky two word class name?
那是因为时髦的两个字类名吗?
2 个解决方案
#1
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.
您必须已生成menu_item或menuItem或MenuItem。除非你说出来,否则它不知道一个词停在哪里而另一个词开始。
Also, for your link_to
s, you just need to append _path
:
另外,对于你的link_tos,你只需要附加_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>
#2
The Pluralizer shows you show things should be named according to the Rails' conventions.
Pluralizer显示您应该根据Rails的约定来显示事物。
#1
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.
您必须已生成menu_item或menuItem或MenuItem。除非你说出来,否则它不知道一个词停在哪里而另一个词开始。
Also, for your link_to
s, you just need to append _path
:
另外,对于你的link_tos,你只需要附加_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>
#2
The Pluralizer shows you show things should be named according to the Rails' conventions.
Pluralizer显示您应该根据Rails的约定来显示事物。