I have a products index which has a list of categories. I used named scopes in my products model for each category, with each category in the view having a link routing users to a products index filtered accordingly. I have a list of routes for each scope. In the view, I want to replace the route path dynamically with a variable such as VAR_products_path. What's the proper syntax for it?
Products index
- @categories.each do |cat|
- @product = Product.where("category_id = ?", cat.id)
= link_to "#{cat.category_name}", cat.category_name_products_path# architecture_products_path or arts_products_path
Products controller
def architecture
params[:category]
@categories = Category.all
@products = Product.architecture
render action: :index
end
Routes file
resources :products do
collection do
get :architecture
get :arts
get :business
...
Product model
scope :architecture, -> { where(category_id: 1) }
scope :arts -> { where(category_id: 2) }