How to DRY up routes in Rails 3
In Rails 3, given routes like
get 'about/terms', :as => 'terms'
get 'about/privacy', :as => 'privacy'
get 'about/jobs', :as => 'career'
get 'about/feedback', :as => 'feedback'
get 'about/contact', :as => 'contact'
get 'abou开发者_如何学Got/us', :as => 'about'
How to DRY it up?
Recon something like this would do it:
['terms', 'privacy', 'jobs', 'feedback', 'contact' ,'us'].each { |r|
get "about/#{r}", :as => r
}
if about is a controller or you hava a controller for your static pages
['terms', 'privacy', 'jobs', 'feedback', 'contact' ,'us'].each { |r|
get "/#{r}", :controller => 'about', :action => r
}
精彩评论