0
以前我是成功呈現一個客戶資源,包括它的使用下面的代碼,嵌套的優惠資源:渲染JSON:範圍的子資源
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?