简体   繁体   English

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

[英]Rails: Routing without plurals gives strange helpers

I am getting a strange named helpers with this setup: 我在此设置中得到了一个奇怪的命名助手:

In config/routes.rb I have: 在config / routes.rb中,我有:

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

rake routes outputs this: 耙路输出:

              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"}

and I do have plurals turned off: 我确实关闭了复数:

ActiveRecord::Base.pluralize_table_names = false

but I get this error: 但是我得到这个错误:

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

This is related to this question which I will delete soon: Rails: routing and path helpers 这与这个问题有关,我将很快删除: Rails:路由和路径助手

This has nothing to do with pluralizing. 这与多元化无关。 YOu need to use search_qtl_table_index_path when you reference it rather than just search_qtl_table_index (you need to add the _path to the end). 引用时,您需要使用search_qtl_table_index_path而不是search_qtl_table_index (您需要在末尾添加_path )。

So, your form_tag statement should be: 因此,您的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