Austio correct answer.
However, why are you invoking the Bid model directly? ...
A person can have many bets.
You are obviously creating data from the person model, so why not call the following:
@person = Person.find params[:person_id] @bids = @person.bids
This will create a collection without calling where .
Of course, your method uses only one db request. But even with the above, it is much more intuitive.
-
As an aside, you'll also want to use a conditional expression before your loop:
<% if @bids.any? %> <% @bids.each.... %> <% end %>
The presence of one bet is in order, but the absence of any of them will not lead to the allocation of errors. The above fixes this problem.
source share