0

私は Rails (3.) に少し慣れていないので、名前を変更したルートを使用するにはあなたの助けが必要です。製品を表示および検索するには、次のルートがあります。

  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

/store/product/home のようなパスではなく、/products/home に名前を変更したかったのです。

したがって、変更されたルートは次のようになります。

  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

Rails 3.2.1 を使用していることに注意してください。

あなたが提供できるどんな助けも大歓迎です。

4

1 に答える 1

1

私が理解しているように、/store 名前空間を削除したいだけですか?

交換

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

namespace :product do 
  resources :home
  resources :search
end 

構造上の理由で名前空間を保持したい場合は、試してください

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

お役に立てれば!

于 2012-05-13T16:59:26.360 に答える