Rails:没有复数的路由给出了奇怪的帮助

我正在使用此设置获得一个奇怪的命名助手:

在config / routes.rb中我有:

Qtl::Application.routes.draw do resources :qtl_table do collection do get 'search' end end ... end 

rake routes输出:

  search_qtl_table_index GET /qtl_table/search(.:format) {:action=>"search", :controller=>"qtl_table"} qtl_table_index GET /qtl_table(.:format) {:action=>"index", :controller=>"qtl_table"} POST /qtl_table(.:format) {:action=>"create", :controller=>"qtl_table"} new_qtl_table GET /qtl_table/new(.:format) {:action=>"new", :controller=>"qtl_table"} edit_qtl_table GET /qtl_table/:id/edit(.:format) {:action=>"edit", :controller=>"qtl_table"} qtl_table GET /qtl_table/:id(.:format) {:action=>"show", :controller=>"qtl_table"} PUT /qtl_table/:id(.:format) {:action=>"update", :controller=>"qtl_table"} DELETE /qtl_table/:id(.:format) {:action=>"destroy", :controller=>"qtl_table"} 

而我确实关闭了复数:

 ActiveRecord::Base.pluralize_table_names = false 

但我得到这个错误:

 undefined local variable or method `search_qtl_table_index' for #<#:0x8056a2338> 

这与我将很快删除的这个问题有关: Rails:路由和路径助手

这与复数无关。 你引用它时需要使用search_qtl_table_index_path ,而不仅仅是search_qtl_table_index (你需要在末尾添加_path )。

所以,你的form_tag语句应该是:

 <%= form_tag search_qtl_table_index_path, :method => 'get' do %>