0

私はThings要素を足場にしました:

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)は正しい名前だと思いましたが、それでもエラーが発生します

ありがとう。

4

2 に答える 2

2

このメソッドは、routes.rbファイルから取得されます。リソース:thing defineがある場合、このメソッドはすべてコントローラー/ビューで定義されます。

config/routes.rb次の場合はファイルを確認してください。

map.resources :things

このリソースがない場合、このメソッドは定義されていません。

Ruby on Railsガイドでこのリソースについて確認してください:http://guides.rubyonrails.org/routing.html

あなたはレーキタスクでこのルートのすべてを知ることができます:

rake routes

于 2010-04-01T13:17:57.133 に答える
0

とった!方法は、によって提案されたとおりでなければなりません

rake routes

ただし、接尾辞_pathが必要です。

<%= link_to 'Edit', edit_wip_thing_path(@thing) %>
于 2010-04-09T08:00:44.780 に答える