我搭建的事情元素:通過腳手架生成的視圖中的壞函數調用是什麼?
script/generate scaffold wip/thing name:string
,並得到了在視圖一些無效的函數調用,如:
<td><%= link_to 'Edit', edit_thing_path(thing) %></td>
由此引發此錯誤:
ActionView::TemplateError (undefined method `edit_thing_path' for #<ActionView::Base:0xb5c00944>) on line #11 of app/views/wip/things/index.html.erb:
8: <tr>
9: <td><%=h thing.name %></td>
10: <td><%= link_to 'Show', thing %></td>
11: <td><%= link_to 'Edit', edit_thing_path(thing) %></td>
12: <td><%= link_to 'Destroy', thing, :confirm => 'Are you sure?', :method => :delete %></td>
13: </tr>
14: <% end %>
什麼與該功能的?它在哪裏?它是某種AUTOMAGIC東西,或者我需要實現它 -
我已經在路線定義與命名空間資源(如果有的話應該在哪裏去了?):
map.namespace :wip do |wip|
wip.resources :things
end
耙路線給了我這樣的:
wip_things GET /wip/things(.:format) {:action=>"index", :controller=>"wip/things"}
POST /wip/things(.:format) {:action=>"create", :controller=>"wip/things"}
new_wip_thing GET /wip/things/new(.:format) {:action=>"new", :controller=>"wip/things"}
edit_wip_thing GET /wip/things/:id/edit(.:format) {:action=>"edit", :controller=>"wip/things"}
wip_thing GET /wip/things/:id(.:format)
我認爲這些名稱(wip_thing,new_wip_thing)是正確的名稱,但它仍然給我的錯誤
感謝。
我有這個資源,但在命名空間中定義: map.namespace:WIP做| WIP | wip.resources:東西 結束 這是不是有什麼問題? – meta 2010-04-05 07:09:36
是的。腳手架定義了沒有命名空間的路由。你需要用這個名字空間來定義URL。查看耙路線查看真實路線 – shingara 2010-04-05 17:59:32
好的,我跑耙路線,並得到「 new_wip_thing GET /wip/things/new(.:format){:action =>」new「,:controller =>」wip/things 「} 」 因此,我試圖在我的視圖中使用「new_wip_thing」,但它仍然會引發錯誤。任何想法我做錯了什麼? – meta 2010-04-07 10:41:07