【发布时间】:2011-09-27 10:01:03
【问题描述】:
我有以下类在我的单元测试中运行良好,但我觉得它可以更简单。
class License < ActiveRecord::Base
scope :active, lambda {
where("active_from <= ?", Date.today).order("version_number DESC")
}
end
def current_license
return License.active.first
end
public :current_license
我尝试将.first 附加到lambda 子句中,但这会导致错误。
我如何告诉scope我只想要第一个结果,从而完全消除方法current_license?
【问题讨论】:
标签: ruby activerecord scope simplification