Ruby on Rails - 路由错误,转到“show”而不是“index”

时间:2013-08-12 15:43:53

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2

我有一个基本主页,其中包含我想要访问的商家/ index.html.erb

<%= link_to("Go to businesses index page", {:controller=>"businesses", :action =>"index"}) %>

当我点击此链接时,我收到路由错误:

No route matches {:action=>"show", :controller=>"businesses"}

我的routes.rb文件如下:

RailsProject::Application.routes.draw do
 get "welcome/index"

 root :to => 'welcome#index'

 get "businesses/index"
 resources :businesses
end

rake routes让我:

   welcome_index GET    /welcome/index(.:format)       welcome#index
      businesses GET    /businesses(.:format)          businesses#index
                 POST   /businesses(.:format)          businesses#create
    new_business GET    /businesses/new(.:format)      businesses#new
   edit_business GET    /businesses/:id/edit(.:format) businesses#edit
        business GET    /businesses/:id(.:format)      businesses#show
                 PUT    /businesses/:id(.:format)      businesses#update
                 DELETE /businesses/:id(.:format)      businesses#destroy
            root        /                              welcome#index
businesses_index GET    /businesses/index(.:format)    businesses#index

我正在使用rails版本3.2

1 个答案:

答案 0 :(得分:1)

问题在于我的业务/索引中有一行读数

<%= link_to 'show', business_path %>

应该是

<%= link_to 'show', business_path(business) %>