我已经优惠券模式在这个模型文件我有一个suitable_for_use method.I要列出优惠券如果coupon.suitable_for_use ==真。就是有什么短的方式来做到这一点?我写了这段代码,但它不起作用。轨道模型行动检查
@coupons = []
coupons = Coupon.all.each do |coupon|
if coupon.suitable_for_use
@coupons << coupon
end
end
@coupons = coupons
suitable_for_use方法
def suitable_for_use
result = true
if is_used?
result = false
elsif self.start > Time.now.in_time_zone
result = false
elsif self.end < Time.now.in_time_zone
result = false
end
return result
end
你可以粘贴'suitable_for_use'的代码吗? – Cluster 2013-02-24 02:27:52
什么是is_used的代码?我在问,因为这里最好的选择是一个AR范围。 – Cluster 2013-02-24 02:46:36