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
1
  • 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". Commented Aug 7, 2015 at 5:34

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.