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 %>

那个功能是怎么回事?它在哪里?它是某种自动化的东西还是我需要实现它(如果是这样 - 它应该去哪里?)

我在具有命名空间的路由中定义了资源:

  map.namespace :wip do |wip|
    wip.resources :things
  end

rake routes 给了我这个:

                                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 文件。如果您有资源:事物定义,则所有此方法都在您的控制器/视图中定义。

如果您是,请检查您的config/routes.rb文件:

map.resources :things

如果您没有此资源,则未定义此方法。

在 Ruby on Rails 指南上查看此资源:http: //guides.rubyonrails.org/routing.html

您可以通过 rake 任务了解所有这些路线:

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 回答