Ciao ho questo modelloOrdina in ordine crescente Rails
voce Modello
class Inventory::Item < ActiveRecord::Base
has_many :types, :class_name => "ItemType"
attr_accessible :name
end
Modello item_type
class Inventory::ItemType < ActiveRecord::Base
belongs_to :item
attr_accessible :number
end
poi diciamo controller voglio ordinare i tipi (che ha classe ItemType) in ordine crescente in base al nome dell'articolo. Come lo faccio?
Ad esempio,
- ItemType numero = 1 ha Itemname = Tabella
- ItemType numero = 2 ha Itemname = Sedia
- ItemType numero = 3 ha Itemname = Finestra
- ItemType numero = 4 ha il nome dell'oggetto = Computer
Così, invece di smistamento a partire dal numero, lo voglio ordinati in base item.name (ASC) come questo:
- ItemType numero = 2 ha il nome dell'oggetto = Chair
- ItemType numero = 4 ha il nome dell'oggetto = Computer
- ItemType numero = 1 ha nome dell'oggetto = Tabella
- ItemType numero = 3 ha nome dell'oggetto = Finestra