0
I cannot sort my array in descending id order.
<%@vendas = Vendas.find(:all,:order=>"id, DESC")%>
0
I cannot sort my array in descending id order.
<%@vendas = Vendas.find(:all,:order=>"id, DESC")%>
1
Friend, I don’t know how your code works, because the find method requires the ID of the object you want to rescue.
Try using the new Ruby syntax instead of rockets. Also try to use spacing to make your code more readable.
The correct code to do what you want is the following:
<% @vendas = Vendas.order("id DESC") %>
Another thing, I recommend moving this line of code to a controller, because it’s not good practice to leave the vision responsible for tasks like these.
In your controller you could do: @ultimas_vendas = Vendas.order("id DESC")
And in the view just call @ultimas_sales.
It is important to note that an array is not returned, but an Activerecord_relation.
0
Correct method:
<%@vendas = Vendas.find(:all,:order=>"id DESC")%>
Browser other questions tagged array ruby-on-rails classification
You are not signed in. Login or sign up in order to post.
That’s the answer?
– Math
@Math seems to me yes, the difference is the comma.
– Jorge B.