3

routes.rb

Rails.application.routes.draw do
  root to: 'visitors#index'
  
  resources :states do
    resources :cities do
      get 'listings'
    end
  end

end

I am looking to have my GET URL set up like: ../state.id/city.id/listings.id

I am using friendly_id so the urls will read like:

../OR/Portland/2011-ford-truck
Community
  • 1
  • 1
baconck
  • 386
  • 2
  • 5
  • 19
  • Looks like what you really want is a triple nested route, instead of get 'listings', try using resources :listings, this will give you "../state.id/city.id/listings.id". – Pierre Aug 07 '15 at 05:34

1 Answers1

3

Listing is it's own model (resource) too in this case. You will also need a resources for listing. If it only has a show action, you can limit it like this:

resources :states do
  resources :cities do
    resources :listings, only: [:show]
  end
end
steakchaser
  • 5,198
  • 1
  • 26
  • 34