2011-02-04 76 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