Apologies for the long wined title, in my app I am trying to retrive e the last record from the database that matches the params I have passed to it.
@goals = Weight.last(:is_goal=>true,:user_id=>@user.id)
In my views I want to run a conditional that checks if there are any present and if it has it will display a div.
<% if @goals.any? %>
<% @goals.each do |goal| %>
<p><%= goal.amount %></p>
<% end %>
<% end %>
But for some reason this throws a no method error NoMethodError at /
undefined method 'any?'
. If I change the .last
to .all
it works
@goals = Weight.all(:is_goal=>true,:user_id=>@user.id)
Is there any reason behind this or have I found a bug?