开发者

How to DRY up routes in Rails 3

开发者 https://www.devze.com 2023-01-29 20:15 出处:网络
In Rails 3, given routes like get \'about/terms\', :as => \'terms\' get \'about/privacy\', :as => \'privacy\'

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
  }
0

精彩评论

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

关注公众号