Rails:没有复数的路由会给奇怪的助手 [英] Rails: Routing without plurals gives strange helpers

查看:62
本文介绍了Rails:没有复数的路由会给奇怪的助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过这种设置,我得到了一个奇怪的命名助手:

I am getting a strange named helpers with this setup:

在config / routes.rb中,我有:

In config/routes.rb I have:

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

我确实关闭了复数形式:

and I do have plurals turned off:

ActiveRecord::Base.pluralize_table_names = false

但出现此错误:

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

推荐答案

这与复数无关。您引用它时需要使用 search_qtl_table_index_path 而不是仅仅使用 search_qtl_table_index (您需要添加 _path 到结尾)。

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).

因此,您的 form_tag 语句应为:

So, your form_tag statement should be:

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

这篇关于Rails:没有复数的路由会给奇怪的助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆