具有相同 :as in rails 的两个范围
Two scopes with the same :as in rails
我有一些 rails 3 条完美运行的路由,用于使用不同模块对 API 进行版本控制:
Rails.application.routes.draw do
scope module: :v2, constraints: Constraints::ApiVersion.new(versions: [2, 2.1], default: false) do
scope 'feedback/:id' do
get 'summary', controller:'summary', action: 'summary', as: 'response_summary'
end
end
scope module: :v1, constraints: Constraints::ApiVersion.new(versions: 1, default: true) do
scope 'feedback/:id' do
get 'summary', controller:'summary', action: 'summary', as: 'response_summary'
end
end
end
但是现在在 rails 5 中,我得到这个错误:
Invalid route name, already in use: 'response_summary' (ArgumentError)
You may have defined two routes with the same name using the :as
option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with resources
as explained here:
http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
有没有办法让 :as
在 Rails 5 中保持不变?
如果我将 v1
更改为不同的 :as
,路径似乎保持不变,正如@kasperite 指出的那样。
response_summary GET /feedback/:id/summary(.:format) /v2/summary#summary
response_summary_v1 GET /feedback/:id/summary(.:format) /v1/summary#summary
response_summary_path
和 response_summary_v1_path
路径看起来是一样的
2.5.1 :017 > response_summary_v1_path(5)
=> "/feedback/5/summary"
2.5.1 :018 > response_summary_path(5)
=> "/feedback/5/summary"
我有一些 rails 3 条完美运行的路由,用于使用不同模块对 API 进行版本控制:
Rails.application.routes.draw do
scope module: :v2, constraints: Constraints::ApiVersion.new(versions: [2, 2.1], default: false) do
scope 'feedback/:id' do
get 'summary', controller:'summary', action: 'summary', as: 'response_summary'
end
end
scope module: :v1, constraints: Constraints::ApiVersion.new(versions: 1, default: true) do
scope 'feedback/:id' do
get 'summary', controller:'summary', action: 'summary', as: 'response_summary'
end
end
end
但是现在在 rails 5 中,我得到这个错误:
Invalid route name, already in use: 'response_summary' (ArgumentError) You may have defined two routes with the same name using the
:as
option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created withresources
as explained here: http://guides.rubyonrails.org/routing.html#restricting-the-routes-created
有没有办法让 :as
在 Rails 5 中保持不变?
如果我将 v1
更改为不同的 :as
,路径似乎保持不变,正如@kasperite 指出的那样。
response_summary GET /feedback/:id/summary(.:format) /v2/summary#summary
response_summary_v1 GET /feedback/:id/summary(.:format) /v1/summary#summary
response_summary_path
和 response_summary_v1_path
路径看起来是一样的
2.5.1 :017 > response_summary_v1_path(5)
=> "/feedback/5/summary"
2.5.1 :018 > response_summary_path(5)
=> "/feedback/5/summary"