我有三个规则routes.rb
:
match ":topic", to: 'topics#show', via: :get, as: :topic
match ":topic/:multi_city(/:year(/:month))", to: "multi_cities#show", via: :get, as: :multi, constraints: {multi_city: /.*\+.*/}
scope ":topic" do
scope ":city" do
match "organizers", to: 'organizers#index', via: :get, as: :topic_organizers
match "(:year(/:month))", to: "communities#show", via: :get, as: :community
end
end
目的是按顺序涵盖以下三种情况:
/football/ # only the topic
/football/chicago+seattle+portland/ # a topic and a combination of cities
/football/chicago # a topic and a single city
规则自己起作用,但问题是它们相互干扰。
目前第一条规则没有得到应用,因为第二条规则正在捕获这些请求,尽管我试图限制第二条规则只捕获带有包含+
标志的次要部分的网址。
如何构造第二条规则,使其仅捕获包含具有两个段的 URL 的请求(并且第二段必须包含加号)?