简体   繁体   English

Rails 2.3.8路由,如何在嵌套资源上创建没有控制器名称的路由?

[英]Rails 2.3.8 routing, how do I create a route without a controller name on nested resources?

Well I have the following code for routing with nested resources: 好吧,我有以下代码用于使用嵌套资源进行路由:

  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

The thing is I don't want all those ':as =>' to be on the url, by this I mean that I don't want the controllers names on the url, istead of generating /cidades/curitiba/ofertas/1 I only want /curitiba/1. 问题是我不希望所有这些':as =>'都出现在url上,这意味着我不希望url上的控制器名称,而是生成/ cidades / curitiba / ofertas / 1我只想要/ curitiba / 1。

I've tried :path_prefix and :as => "", but those did not work. 我已经尝试过:path_prefix和:as =>“”,但是这些都不起作用。

any help? 有什么帮助吗?

thanks 谢谢

What if you try this after the map.resources definition in routes.rb? 如果在route.rb中的map.resources定义之后尝试此操作怎么办?

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

Then you do whatever you want in offers_controller#show 然后,您可以在offers_controller#show中执行任何操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM