繁体   English   中英

Rails:没有复数的路由会给奇怪的助手

[英]Rails: Routing without plurals gives strange helpers

我在此设置中得到了一个奇怪的命名助手:

在config / routes.rb中,我有:

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

耙路输出:

              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 #<#<Class:0x8056a3fa8>:0x8056a2338>

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

这与多元化无关。 引用时,您需要使用search_qtl_table_index_path而不是search_qtl_table_index (您需要在末尾添加_path )。

因此,您的form_tag语句应为:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM