baconck
baconck

Reputation: 406

Rails 4 nested routes

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

Upvotes: 3

Views: 43

Answers (1)

steakchaser
steakchaser

Reputation: 5249

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

Upvotes: 3

Related Questions