Is there any way to DRY up these routes. There is a pattern to them:
get "articles/new" => "articles#new", :as => :new_article
post "articles/new" => "articles#create", :as => :create_article
get "articles/:slug/edit" => "articles#edit", :as => :edit_article
get "stores/:id/articles/new" => "articles#new", :as => :new_store_article, :defaults => { :scope => 'store' }
post "stores/:id/articles/new" => "articles#create", :as => :create_store_article, :defaults => { :scope => 'store' }
get "stores/:id/articles/:slug/edit" => "articles#edit", :as => :edit_store_article, :defaults => { :scope => 'store' }
get "warehouses/:id/articles/new" => "articles#new", :as => :new_warehouse_article, :defaults => { :scope => 'warehouse' }
post "warehouses/:id/articles/new" => "articles#create", :as => :create_warehouse_article, :defaults => { :scope => 'warehouse' }
get "warehouses/:id/articles/:slug/edit" => "articles#edit", :as => :edit_warehouse_article, :defaults => { :scope => 'warehouse' }
Thanks in advance!
I wanted an elegant solution and I seem to have found one. Basically, adding a helper method that I can use in my routes file by putting this in
lib/routes_helper.rb:Then in my
routes.rbfile, I can simply just do