开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜