【发布时间】:2014-01-23 18:28:00
【问题描述】:
我有两个模型。
class Shoe < ActiveRecord::Base
has_many :sizes, :dependent => :destroy
scope :brand_asc , order('brand ASC')
scope :brand_desc , order('brand DESC')
attr_accessible :brand ,:model
end
class Size < ActiveRecord::Base
belongs_to :shoe
scope :size_brand_asc , order("#{self.shoe.brand} ASC")
scope :size_brand_desc , order("#{self.shoe.brand} DESC")
end
It is very easy to call named scope on Shoe model like below.
@shoes = Shoe.brand_asc
But i want to sort sizes on the base of "brand" that is attribute of shoe model.so this
对我不起作用,如下所示。
@sizes = Size.size_brand_asc # giving error
我如何根据鞋子品牌对尺码进行排序
【问题讨论】: