在Rails中对非资源路由进行分组5

问题描述 投票:1回答:2

我有2条这样的路线:

get '/quotation/cep_validator', to: 'quotation#cep_validator'
get '/quotation/price', to: 'quotation#price'

它们不是RESTful,但正如您所看到的,它们在URL和同一个控制器中具有相同的开头。

有没有办法将它们组合在一起,类似于资源路线?

route :quotation do
  get 'cep_validator'
  get 'price'
end
ruby-on-rails routes ruby-on-rails-5 rails-routing
2个回答
1
投票

试试这个:

resource :quotation, only: [] do
  collection do
    get :cep_validator
    get :price
  end
end

希望这会帮助你。


1
投票

这就是你要找的东西:

controller :quotation do
  get 'cep_validator' => :cep_validator
  get 'price' => :price
end
    
© www.soinside.com 2019 - 2024. All rights reserved.