Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 251
baconck Avatar asked Dec 14 '25 06:12

baconck


1 Answers

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
like image 153
steakchaser Avatar answered Dec 15 '25 20:12

steakchaser