我正在尝试添加可选的路由作用域或名称空间,但是在使其工作时遇到了一些麻烦。
我想像这样匹配网址:
https://www.mydoamin.com/en/cars/Audi
# Should be matched with Parameters: {"locale"=>"en", "brand"=>"Audi"}
https://www.mydoamin.com/en/cars/Audi/A4
# Should be matched with Parameters: {"locale"=>"en", "brand"=>"Audi", "car_model" => "A4"}
https://www.mydoamin.com/en/cars/in/Berlin
# Should be matched with Parameters: {"locale"=>"en", "region"=>"Berlin"}
https://www.mydoamin.com/en/cars/in/Berlin/Audi
# Should be matched with Parameters: {"locale"=>"en", "region"=>"Berlin", "brand"=>"Audi"}
https://www.mydoamin.com/en/cars/in/Berlin/Audi/A4
# Should be matched with Parameters: {"locale"=>"en", "region"=>"Berlin", "brand"=>"Audi", "car_model" => "A4"}
我当前的尝试如下:
scope ':locale' do
scope 'cars' do
scope '/in' do
get ":region/(:brand)/(:car_model)" => 'cars_search#search', :as => :cars_search
end
get "(:brand)/(:car_model)" => 'cars_search#search', :as => :cars_search
end
end
但是,如果没有in
位置范围,例如https://www.mydoamin.com/en/cars/Audi/A4