Custom routes for the same controller. I have many semi-static pages in my app (actually stored in my database with a group and page name field), they are grouped by product and then subject, for example Cars: tires, Wheels, Radio, Windshield Homes: Doors, Windows, Roof Products and Services: data services
I would prefer not to make a new controller for each group. However, I am trying to get different URL paths that are descriptive. For example:
domain.com/cars/tires_and_spokes
domain.com/cars/wheels
domain.com/homes/doors_and_knobs
domain.com/homes/windows
domain.com/products_and_services/data_service
currently, all I have is
domain.com/pages/cars_tires_and_spokes
etc.
but I prefer the former.
Routes:
pages_from_DB =[
{group:"cars", name:"tires and spokes"}
{group:"cars", name:"wheels"}
{group:"homes", name:"tires and spokes"}
{group:"homes", name:"windows"}
]
pages = %w[
cars_tires_and_spokes
cars_wheels
homes_doors_and_knobs
homes_windows
products_and_services_data_service
]
pages.each do |page|
get page, controller: "pages", action: page
end
Controller:
class PagesController < ApplicationController
pages_from_DB =[
{group:"cars", name:"tires and spokes"}
{group:"cars", name:"wheels"}
{group:"homes", name:"tires and spokes"}
{group:"homes", name:"windows"}
]
pages = %w[
cars_tires_and_spokes
cars_wheels
homes_doors_and_knobs
homes_windows
products_and_services_data_service
]
pages.each do |page|
define_method(page) do
end
end
end