I’m getting the error:
ActiveRecord::RecordNotFound in ShoesController#choose_store_shoes
Couldn't find Store without an ID
Keep in mind that shoes belong to a Store. This all takes place in the shoes controller, beginning in the see_shoes action and then when a user clicks on a Store it uses the choose_store_shoes action. This should show the store and the shoes. I just need help actually getting to the page.
ShoesController
def see_stores
@stores = Store.paginate(:page => params[:page], :per_page => 20)
end
def choose_store_shoes
@store = Store.find(params[:id])
end
My Routes:
resources :shoes do
collection do
get 'see_stores'
get 'choose_store_shoes'
end
end
Then my view where you click on a store and it should show it:
<% for store in @stores %>
<%= link_to choose_store_shoes_shoes_path(store.id) do %>
<%= store.name %>
<%= store.location %>
<% end %>
<% end %>
I think I’m linking or routing it incorrectly. What would be the right way?
Thank you in advance.
You’re parsing :id, when there is no :id in the url scheme. You need to fix your routes.
In your routes.rb, change
collection dotomember doso that the url scheme accepts an :id.After you have made this change to your route, you can then specify which store you want with the proper id:
127.0.0.1:3000/shoes/:id/choose_store_shoes