This is not a very good solution as it violates the RESTful conventions.
In Rails flavor REST GET /resource_name/:id maps to the show route. In the case of get "/items/(:brand)", to: "items#index", as: :items this creates an ambiguity (is the segment an item id or a brand?) when the router matches the requests and the first declared route will win which is hardly desirable.
A better solution is to declare it as a nested resource:
resources :brands, only: [] do
resources :items, only: [:index], module: :brands
end
Prefix Verb URI Pattern Controller#Action
brand_items GET /brands/:brand_id/items(.:format) brands/items#index
# app/controllers/brands/items_controller.rb
module Brands
class ItemsController < ::ApplicationController
before_action :set_brand
# GET /brands/:brand_id/items
def index
@items = @brand.items
end
def set_brand
@brand = Brand.find(params[:brand_id])
end
end
end
get "/items/(:brand)", to: "items#index", as: :itemsis a pretty bad route as it violates the RESTful conventions and creates and ambiguity with the normal show route (GET /items/:id). Why can't you change it to something better likeGET /brands/:brand_id/items?