Ok, I need help with this one. I have defined a resource with non-standard actions. It looks like this in config/routes.rb
:
1 Upload::Application.routes.draw do
2
3 resources :lib_imports, :only => [:index, :new, :create, :show] do
4 get 'reimport', :on => :member
5 end
...
I can see the routes I expect when I run rails routes
$ rake routes
reimport_lib_import GET /lib_imports/:id/reimport(.:format) {:action=>"reimport", :controller=>"lib_imports"}
lib_imports GET /lib_imports(.:format) {:action=>"index", :controller=>"lib_imports"}
new_lib_import GET /lib_imports/new(.:format) {:action=>"new", :controller=>"lib_imports"}
edit_lib_import GET /lib_imports/:id/edit(.:format) {:action=>"edit", :controller=>"lib_imports"}
lib_import GET /lib_imports/:id(.:format) {:action=>"show", :controller=>"lib_imports"}
...
I'm trying to use the named route "reimport_lib_import" in the index view for the LibImport model, index.html.erb
, part of which looks like this:
...
10 <% @lib_imports.each do |lib_import| %>
11 <tr>
12 <td><%= lib_import.spreadsheet %></td>
13 <td><%= link_to 'Show', lib_import %></td>
14 <td><%= link_to 'Re-import', reimport_lib_import %></td>
15 </tr>
16 <% end %>
...
However, the result is that the browser displays an error. The relevant part of the error is:
Showing /home/mike/rails_projects/experiments/upload/app/views/lib_imports/index.html.erb where line #14 raised:
undefined local variable or method `reimport_lib_import' for #<#<Class:0x007fa938a06778>:0x007fa938950720>
Extracted source (around line #14):
11: <tr>
12: <td><%= lib_import.spreadsheet %></td>
13: <td><%= link_to 'Show', lib_import %></td>
14: <td><%= link_to 'Re-import', reimport_lib_import %></td>
15: </tr>
16: <% end %>
17: </table>
My the question is this: why does Rails complain about reimport_lib_import
when I try to use it? The fact that it sails by lib_import
on the previous line without complaint but trips over this one has me quite puzzled Anyone got any ideas?