Sort ruby array by updated_at -


What I want to do is get the latest item from my model and they have sorted an array (first of all Latest items) "updated_at" by attribute.

Somewhere there is an error, but I can not find it:

  @results = Array.new note.field (: all,: border => 3 ,: Order = & gt; "Created DASC"). Do each. Items | @ Ruits & lt; & Lt; Item end picture Find (: All ,: Border => 3 ,: Order = & gt; "Created DASC") Do each. Items | @ Ruits & lt; & Lt; End of item @ result = @ result sort_by {| Results | As a result, .updated_at}  

You need to compare the sort. `

@results = Array.new note.find (: all ,: limit => 3 ,: order = & gt;" made_at DESC "). Do each. Items | @ Ruits & lt; & Lt; Item end picture Find (: All ,: Border => 3 ,: Order = & gt; "Created DASC") Do each. Items | @ Ruits & lt; & Lt; Item end @ results.sort! {| A, b A.updated_at & lt; = & Gt; B.updated_at}

This will sort the @results array in place.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -