katie
katie

Reputation: 2951

What to use instead of find_with_ids( )?

The code below displays peferctly what i want to accomplish (show store name and item name).But when i subtitute @[email protected]_with_ids(62) with @[email protected](params[:id]) i get an error Couldn't find Deal without an ID.What method should i use to fetch deal ID dynamically?The relationship between the Deal and store model is has many :through.

controller

  @[email protected]
  @[email protected]_with_ids(62)
  @[email protected](params[:store_id])

view

   <% @deal.each do |deal| %>
   <%=deal.item_name %>
   <%end%>
    <%[email protected]_name %>

Upvotes: 0

Views: 441

Answers (2)

Max
Max

Reputation: 15985

What about

Deal.find(params[:id]) rescue nil

Upvotes: 1

jefflunt
jefflunt

Reputation: 33954

That error means that params[:id] is empty. Check your params hash to see what it contains, and verify that your action is getting the input it expects.

You are absolutely using the .find method as intended, so I don't think that's the issue.

Upvotes: 1

Related Questions