以前我使用下面的代码成功地呈现了一个客户资源,包括它的嵌套折扣资源:
class Discount < ActiveRecord::Base
belongs_to :customer
end
format.json { render json: Customer.find(params[:id]), :include => { :discounts =>
{:include => {...}
}}
}}
我后来在我的折扣中添加了一个范围,即
class Discount < ActiveRecord::Base
belongs_to :customer
scope :current, where('(begin_on <= ? OR begin_on IS NULL) AND (? <= end_on OR end_on IS NULL)', Date.today, Date.today)
end
如何使上述 json 调用仅呈现这些当前折扣而不是所有 Customer.discounts?