How to dry routes in Rails 3

In Rails 3, given routes, for example

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 'about/us', :as => 'about'

How to dry it?

+3
source share
2 answers

Repeat something like this:

['terms', 'privacy', 'jobs', 'feedback', 'contact' ,'us'].each { |r|
    get "about/#{r}", :as => r 
}
+4
source

if about is a controller or you hava controller for your static pages

  ['terms', 'privacy', 'jobs', 'feedback', 'contact' ,'us'].each { |r|
      get "/#{r}", :controller => 'about', :action => r
  }
+1
source

Source: https://habr.com/ru/post/1779727/


All Articles