【问题标题】:Rails: Routing without plurals gives strange helpersRails:没有复数的路由提供了奇怪的助手
【发布时间】:2012-01-04 16:15:06
【问题描述】:

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

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

这与我将很快删除的这个问题有关: Rails: routing and path helpers

【问题讨论】:

    标签: ruby-on-rails routing helpers


    【解决方案1】:

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

    所以,你的form_tag 声明应该是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 2013-05-20
      • 1970-01-01
      • 2023-03-30
      相关资源
      最近更新 更多