我有以下类在我的单元测试中运行良好,但我觉得它可能更简单。
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
完全消除该方法?