0

I've scaffolded Things element:

script/generate scaffold wip/thing name:string

and got some invalid function call in views, like:

<td><%= link_to 'Edit', edit_thing_path(thing) %></td>

Which raise this error:

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

What's with that function? Where is it? Is it some kind of automagic stuff or do I need to implement it (if so - where should it go?)

I have resource defined in routes with namespace:

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

rake routes gives me this:

                                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)  

I assumed that those names (wip_thing, new_wip_thing) are the correct names, but it's still gives me that error

Thanks.

Greg
  • 5,862
  • 1
  • 25
  • 52

2 Answers2

2

This method come from your routes.rb file. If you have a resource :thing define, all of this method are define in your controller/views.

Check on your config/routes.rbfile if you are :

map.resources :things

If you don't have this resource, this methode is not define.

Check about this resource on Ruby on Rails guides : http://guides.rubyonrails.org/routing.html

You can know all of this routes with the rake task :

rake routes

shingara
  • 46,608
  • 11
  • 99
  • 105
  • I have this resource but defined in namespace: map.namespace :wip do |wip| wip.resources :things end is it something wrong with that? – Greg Apr 05 '10 at 07:09
  • Yes it is. The scaffold define route without namespace. You need define the url with this namespace. See rake routes to see the real route – shingara Apr 05 '10 at 17:59
  • Ok, I ran rake routes, and got " new_wip_thing GET /wip/things/new(.:format) {:action=>"new", :controller=>"wip/things"} " So I tried to use "new_wip_thing" in my view, but it still raises an error. Any ideas what am I doing wrong? – Greg Apr 07 '10 at 10:41
0

got it! The method should be as suggested by

rake routes

but should have suffix _path:

<%= link_to 'Edit', edit_wip_thing_path(@thing) %>
Greg
  • 5,862
  • 1
  • 25
  • 52