Rails:没有复数的路由给出了奇怪的助手
我通过此设置得到了一个奇怪的命名助手:
在 config/routes.rb 中,我有:
Qtl::Application.routes.draw do
resources :qtl_table do
collection do
get 'search'
end
end
...
end
rake 路由输出:
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:路由和路径助手
I am getting a strange named helpers with this setup:
In config/routes.rb I have:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与复数无关。引用时需要使用
search_qtl_table_index_path
而不仅仅是search_qtl_table_index
(您需要将_path
添加到末尾)。因此,您的
form_tag
语句应该是:This has nothing to do with pluralizing. YOu need to use
search_qtl_table_index_path
when you reference it rather than justsearch_qtl_table_index
(you need to add the_path
to the end).So, your
form_tag
statement should be: