我有以下代码用于使用嵌套资源进行路由:
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
事情是我不想要所有那些':as =>'在网址上,我的意思是我不想要网址上的控制器名称,而不是生成/ cidades / curitiba / ofertas / 1我只想要/ curitiba / 1.
我试过了:path_prefix和:as => “”,但那些没有用。
任何帮助?
感谢
答案 0 :(得分:1)
如果你在routes.rb中的map.resources定义之后尝试这个怎么办?
match '/:city_name/:id', :to => "offers#show"
然后你在offers_controller#show
中做任何你想做的事