更改单个控制器操作的URI模式

时间:2014-02-20 12:01:08

标签: ruby-on-rails routes

我有以下路线文件:

的routes.rb

root "pages#home"
resources :businesses
match ':id' => 'businesses#show', :via => [:get]

这给了我以下路线:

              Prefix Verb   URI Pattern                       Controller#Action
                root GET    /                                 pages#home
          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
                     PATCH  /businesses/:id(.:format)         businesses#update
                     PUT    /businesses/:id(.:format)         businesses#update
                     DELETE /businesses/:id(.:format)         businesses#destroy
                     GET    /:id(.:format)                    businesses#show

我有一个“商家”表单,完成后会将我重定向到:

http://localhost:3000/businesses/BusinessToShow

如何从此网址重定向中删除控制器名称(商家)?

我是否能够输入一条路线,该路线将仅为business_path更改URI模式?

我特意将路线'匹配':id'=> 'business#show',:via => [:get]'这样可以完成搜索并执行show动作而不需要控制器名称,这只是导致问题的重定向。

提前谢谢

1 个答案:

答案 0 :(得分:1)

以下路线配置将解决您的问题。

  resources :businesses, :except => [:show, :update, :destroy]
  resources :businesses, :path => '/', :only => [:show, :update, :destroy]