Ruby on rails 未定义的方法'has#u index#u path';

Ruby on rails 未定义的方法'has#u index#u path';,ruby-on-rails,ruby,Ruby On Rails,Ruby,我想我已经尝试了StackOverflow上的每一个“未定义方法”问题解决方案,但仍然没有找到一个适合我的情况的解决方案 我有一个名为“Has”的模型,我想我的问题可能与最后的“s”有关。每当我尝试加载has/新url时,都会出现此错误/他工作得很好。只是不新鲜 未定义的方法'has_index_path'用于# Has.rb: class Has < ActiveRecord::Base attr_accessible :bathroom_count, :bedroom_count,

我想我已经尝试了StackOverflow上的每一个“未定义方法”问题解决方案,但仍然没有找到一个适合我的情况的解决方案

我有一个名为“Has”的模型,我想我的问题可能与最后的“s”有关。每当我尝试加载has/新url时,都会出现此错误/他工作得很好。只是不新鲜

未定义的方法'has_index_path'用于#

Has.rb:

class Has < ActiveRecord::Base
  attr_accessible :bathroom_count, :bedroom_count, :neighborhood, :price, :property_type
  belongs_to :trader
end
编辑:以下是rake routes输出:

    traders GET    /traders(.:format)          traders#index
            POST   /traders(.:format)          traders#create
     new_trader GET    /traders/new(.:format)      traders#new
    edit_trader GET    /traders/:id/edit(.:format) traders#edit
         trader GET    /traders/:id(.:format)      traders#show
                PUT    /traders/:id(.:format)      traders#update
                DELETE /traders/:id(.:format)      traders#destroy
          wants GET    /wants(.:format)            wants#index
                POST   /wants(.:format)            wants#create
       new_want GET    /wants/new(.:format)        wants#new
      edit_want GET    /wants/:id/edit(.:format)   wants#edit
           want GET    /wants/:id(.:format)        wants#show
                PUT    /wants/:id(.:format)        wants#update
                DELETE /wants/:id(.:format)        wants#destroy
            has GET    /has(.:format)              has#index
                POST   /has(.:format)              has#create
         new_ha GET    /has/new(.:format)          has#new
        edit_ha GET    /has/:id/edit(.:format)     has#edit
             ha GET    /has/:id(.:format)          has#show
                PUT    /has/:id(.:format)          has#update
                DELETE /has/:id(.:format)          has#destroy
           root        /                           static_pages#index
    add_traders        /add_traders(.:format)      traders#new
                       /traders(.:format)          traders#index
        add_has        /add_has(.:format)          has#new
                       /has(.:format)              has#index
      add_wants        /add_wants(.:format)        wants#new
                        /wants(.:format)            wants#index
编辑3 添加拐点代码段后的新路由。“Has”路由看起来更好,但现在我在任何localhost:3000页面上都遇到了这个错误

No route matches {:action=>"show", :controller=>"has"}
以下是新路线:

    traders GET    /traders(.:format)          traders#index
            POST   /traders(.:format)          traders#create
 new_trader GET    /traders/new(.:format)      traders#new
edit_trader GET    /traders/:id/edit(.:format) traders#edit
     trader GET    /traders/:id(.:format)      traders#show
            PUT    /traders/:id(.:format)      traders#update
            DELETE /traders/:id(.:format)      traders#destroy
      wants GET    /wants(.:format)            wants#index
            POST   /wants(.:format)            wants#create
   new_want GET    /wants/new(.:format)        wants#new
  edit_want GET    /wants/:id/edit(.:format)   wants#edit
       want GET    /wants/:id(.:format)        wants#show
            PUT    /wants/:id(.:format)        wants#update
            DELETE /wants/:id(.:format)        wants#destroy
  has_index GET    /has(.:format)              has#index
            POST   /has(.:format)              has#create
    new_has GET    /has/new(.:format)          has#new
   edit_has GET    /has/:id/edit(.:format)     has#edit
        has GET    /has/:id(.:format)          has#show
            PUT    /has/:id(.:format)          has#update
            DELETE /has/:id(.:format)          has#destroy
       root        /                           static_pages#index
add_traders        /add_traders(.:format)      traders#new
                   /traders(.:format)          traders#index
    add_has        /add_has(.:format)          has#new
                   /has(.:format)              has#index
  add_wants        /add_wants(.:format)        wants#new
                   /wants(.:format)            wants#index

我建议您使用一个名词作为资源的名称,但如果出于某种原因您真的想保留当前名称,您可以使用以下技巧:使用屈折符模块欺骗rails,使其认为“has”的“单数”和“复数”是相同的:

在configs/initializers/indlections.rb中:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'has', 'has'
end

所以我看到那些“哈”路线。。。。我相信这就是问题所在。我不熟悉rails。对此我该怎么办?像
new\u ha
这样的命名路由表明Rails命名屈折不适合您的示例。在所有的名字中都很少见。您可以考虑使用<代码>需求<代码>模型和<代码>提供< /C>模式,其中Rails会正确地命名名称和路由。谢谢托马斯。关于按原样修改模型名称的路由,有什么建议吗?我正在使用一个非常复杂的算法,这个算法是用这些名字为我设计的,我希望不必改变它,但最好使用名词。在以后的代码版本中,欺骗一个系统可能会变得丑陋。啊,现在我在添加屈折变化修改后遇到了这个错误:没有路由匹配{:action=>“show”,:controller=>“has”}确保在运行rake路由时看到
has GET/has/:id(:format)has#show
行。这看起来确实在那里。。。has GET/has/:id(:format)has#show错误的上下文是什么?您试图在原始代码中呈现相同的模板,还是呈现不同的模板?如果不同,请张贴。
No route matches {:action=>"show", :controller=>"has"}
    traders GET    /traders(.:format)          traders#index
            POST   /traders(.:format)          traders#create
 new_trader GET    /traders/new(.:format)      traders#new
edit_trader GET    /traders/:id/edit(.:format) traders#edit
     trader GET    /traders/:id(.:format)      traders#show
            PUT    /traders/:id(.:format)      traders#update
            DELETE /traders/:id(.:format)      traders#destroy
      wants GET    /wants(.:format)            wants#index
            POST   /wants(.:format)            wants#create
   new_want GET    /wants/new(.:format)        wants#new
  edit_want GET    /wants/:id/edit(.:format)   wants#edit
       want GET    /wants/:id(.:format)        wants#show
            PUT    /wants/:id(.:format)        wants#update
            DELETE /wants/:id(.:format)        wants#destroy
  has_index GET    /has(.:format)              has#index
            POST   /has(.:format)              has#create
    new_has GET    /has/new(.:format)          has#new
   edit_has GET    /has/:id/edit(.:format)     has#edit
        has GET    /has/:id(.:format)          has#show
            PUT    /has/:id(.:format)          has#update
            DELETE /has/:id(.:format)          has#destroy
       root        /                           static_pages#index
add_traders        /add_traders(.:format)      traders#new
                   /traders(.:format)          traders#index
    add_has        /add_has(.:format)          has#new
                   /has(.:format)              has#index
  add_wants        /add_wants(.:format)        wants#new
                   /wants(.:format)            wants#index
ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'has', 'has'
end