My users create collections and add listings to each collection. I have a main profile page for each user showing all collections created by that user. Now I want to link from each collection to an individual collection page showing all listings in that collection.
My user view file to show all collections:
<% @collections.each do |collection| %>
<%= image_tag listing.image.url(:thumb) %>
<%= link_to "#{collection.name}", shopcollected_path(collection_id: @collection) %>
<% end %>
When I click on my link I'm taken to the individual collection page (shopcollected.html.erb) just fine, but the listings for that collection aren't being recognized and the page is empty of listings. I know I'm missing one small part, but am stuck again on what that is. I'm still learning about retrieving objects from databases and linking.
My listings_controller:
def shopcollections
@user = User.find(params[:id])
@collections = Collection.where(user: User.find(params[:id])).order("created_at DESC")
end
def shopcollected
@user = User.find(params[:id])
@listings = Listing.where(collection: :collection_id)
end
My individual user 'shopcollected' view file:
<% @listings.each do |listing| %>
<%= image_tag listing.image.url(:medium) %>
<%= listing.name %>`
<% end %>
What am I missing? I believe I need to call all listings by collection, but in order to do so, where do I need to make a change in my code?