Get all from table AND sort?
Using the following code in my controller, I am able to retrieve all rows from my table, but it won't sort by the column last_name
. Any sug开发者_JAVA技巧gestions?
@pi_names = PiName.all(:order => 'pi_names.last_name DESC')
Try
@pi_names = PiName.order('pi_names.last_name DESC').all
Alternative syntax allowing any errors to potentially be caught prior to runtime:
@pi_names = PiName.order(last_name: :desc)
精彩评论