簡體   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