Sort in Ascending Order Rails

后端 未结 5 1609
我寻月下人不归
我寻月下人不归 2021-02-02 08:46

Hi I have this model

Model item

class Inventory::Item < ActiveRecord::Base
  has_many :types, :class_name => \"ItemType\"
  attr_accessible :na         


        
5条回答
  •  太阳男子
    2021-02-02 09:17

    For making ASC (Default sorting mode) for name kind of fields (Alphabets),

    You can use ORDER BY Clause in MySQL
    

    Hence, In Rails you can simply use

    Model.order(:field_name)
    

提交回复
热议问题