2012-05-13 89 views
0

我對Rails(3.)有點新,需要您的幫助來使用重命名的路由。我有以下路線來顯示和搜索產品。Rails 3.2.1 - 重命名路由

namespace :store do 
    namespace :product do 
     resources :home 
     resources :search 
    end 
    end 

而且rake routes呈現以下輸出爲上述資源:

store_product_home_index GET /store/product/home(.:format)      store/product/home#index 
          POST /store/product/home(.:format)      store/product/home#create 
    new_store_product_home GET /store/product/home/new(.:format)     store/product/home#new 
    edit_store_product_home GET /store/product/home/:id/edit(.:format)    store/product/home#edit 
     store_product_home GET /store/product/home/:id(.:format)     store/product/home#show 
          PUT /store/product/home/:id(.:format)     store/product/home#update 
         DELETE /store/product/home/:id(.:format)     store/product/home#destroy 
store_product_search_index GET /store/product/search(.:format)      store/product/search#index 
          POST /store/product/search(.:format)      store/product/search#create 
    new_store_product_search GET /store/product/search/new(.:format)     store/product/search#new 
edit_store_product_search GET /store/product/search/:id/edit(.:format)   store/product/search#edit 
     store_product_search GET /store/product/search/:id(.:format)     store/product/search#show 
          PUT /store/product/search/:id(.:format)     store/product/search#update 
         DELETE /store/product/search/:id(.:format)     store/product/search#destroy 

而不必像/存儲/產品/ home路徑,我想改名爲/產品/家。

所以修改路線看起來應該像下面的:我使用的Rails 3.2.1

store_product_home_index GET /products/home(.:format)      store/product/home#index 
          POST /products/home(.:format)      store/product/home#create 
    new_store_product_home GET /products/home/new(.:format)     store/product/home#new 
    edit_store_product_home GET /products/home/:id/edit(.:format)    store/product/home#edit 
     store_product_home GET /products/home/:id(.:format)     store/product/home#show 
          PUT /products/home/:id(.:format)     store/product/home#update 
         DELETE /products/home/:id(.:format)     store/product/home#destroy 
store_product_search_index GET /products/search(.:format)      store/product/search#index 
          POST /products/search(.:format)      store/product/search#create 
    new_store_product_search GET /products/search/new(.:format)     store/product/search#new 
edit_store_product_search GET /products/search/:id/edit(.:format)   store/product/search#edit 
     store_product_search GET /products/search/:id(.:format)     store/product/search#show 
          PUT /products/search/:id(.:format)     store/product/search#update 
         DELETE /products/search/:id(.:format)     store/product/search#destroy 

注意。

任何幫助,您可以提供非常感謝。

回答

1

據我所知,你只是想刪除/存儲命名空間?

更換

namespace :store do 
    namespace :product do 
     resources :home 
     resources :search 
    end 
    end 

如果你想保留的命名空間結構上的原因嘗試

namespace :store,:path => "" do 
    namespace :product do 
     resources :home 
     resources :search 
    end 
    end 

希望這有助於

namespace :product do 
    resources :home 
    resources :search 
end 

+0

我也想重命名:product namespace to/products –