2011-02-04 70 views
1

嗯,我已經與嵌套資源路由下面的代碼:Rails 2.3.8路由,如何在嵌套資源上創建沒有控制器名稱的路由?

map.resources :cities, :as => "cidade", :only => [:index, :show] do |city| 
    city.resources :offers, :as => "oferta", :only => [:show], :collection => [:recents], :member => [:share, :buy, :add, :add_gift, :remove, :validate_buy, :want_more, :withdraw_credits], :path_names => { :want_more => "quero-mais", :recents => "recentes", :buy => "comprar", :add_gift => "comprar-presente", :share => "compartilhar", :add => "adicionar", :remove => "remover", :validate_buy => "validar-compra", :withdraw_credits => "resgatar-creditos" } do |offer| 
     offer.resources :photos, :as => "fotos", :only => [:index] 
     offer.resources :videos, :as => "videos", :only => [:index, :show] 
     offer.resources :comments, :as => "comentarios", :only => [:index, :new, :create] 
    end 
    end 

事情是我不希望所有那些「:爲=>」要對URL,通過我的意思,我不'不想要控制器名稱的網址,是生成/ cidades/curitiba/ofertas/1我只想要/ curitiba/1。

我試過了:path_prefix和:as =>「」,但那些都不起作用。

有幫助嗎?

感謝

回答

1

如果你在routes.rb中的map.resources定義後嘗試呢?

match '/:city_name/:id', :to => "offers#show" 

然後你做任何你想要在offers_controller#顯示

+0

香港專業教育學院做到了這一點作爲一個變通,但我確實不希望做失去嵌套的資源。 – 2011-02-20 02:14:12