Get everything from AND sort table?

Using the following code in my controller, I can extract all the rows from my table, but not sort by last_name column. Any suggestions?

  @pi_names = PiName.all(:order => 'pi_names.last_name DESC') 
+6
source share
2 answers

Try

  @pi_names = PiName.order('pi_names.last_name DESC').all 
+18
source

Alternative syntax to detect potential errors before runtime:

 @pi_names = PiName.order(last_name: :desc) 
0
source

Source: https://habr.com/ru/post/894663/


All Articles