Reputation: 39
I am trying to show the last updated record of 'weight' from this DB:
I am trying to call it using:
<%= @user.weights.last %>
I didn't get an error but I get this string printed:
<Weight:0x007f80814ab538>
Tried all sorts!
Upvotes: 0
Views: 185
Reputation: 161
get last updated user' weights
@last_weight = @user.weights.order("updated_at DESC").first
the result is:
<Weight:0x007f80814ab538>
And you need to show the attibutes of Weight in your template
<%= @last_weight.attribute_1 %>
<%= @last_weight.attribute_2 %>
Upvotes: 0
Reputation: 2872
What you see is a Weight object being returned. Try calling a field attribute on that:
@user.weights.last.weight
Upvotes: 1