开发者

How can i override a scope route with a named route in rails 3?

开发者 https://www.devze.com 2023-02-18 13:49 出处:网络
I have this scope: scope \":section\", :section => /[a-zA-Z_]+/ do resources :case_studies, :promotions, :events

I have this scope:

scope ":section", :section => /[a-zA-Z_]+/ do
 resources :case_studies, :promotions, :events
end

URL example: :section/case_studies

And i have a named scope:

namespace :admin do
 r开发者_Go百科esources :case_studies, :promotions, :events
end

URL example: admin/case_studies

The problem is the admin case studies, promotions, and events are registering the "admin" namespace portion as a section variable. Is there a way to limit the scope more or have admin take precedence over it?


Routes are executed top-down in your routes.rb file. If you make sure they're in this order:

namespace :admin do
  resources :case_studies, :promotions, :events
end

scope ":section", :section => /[a-zA-Z_]+/ do
  resources :case_studies, :promotions, :events
end

Then the admin routes should take precedent over your section routes.


for precedence move the admin namespace higher up in your routes.rb file

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号