I am trying to sort my data according to the timestamp field in my controller, note that the timestamp field may be null and may have some value. I wrote the following query.
@item = Item.sort_by(&:item_timestamp).reverse
.paginate(:page => params[:page], :per_page =>5)
But this gives an error when I have elements that have the time_timestamp field set to NULL, but the following query is executed.
@item = Item.order(:item_timestamp).reverse
.paginate(:page => params[:page], :per_page => 5)
Can someone tell the difference between the two queries and in what state to use which?
And I use the reverse order to get the last items from the database. Is this the best way or are there other better ways to get the latest data from a database in terms of performance?
source
share