0
想知道是否有可能从一个范围,活动记录抢救救助范围
我的模型
class Question < ActiveRecord::Base
scope :active, -> {where("is_active = 't'")}
validates_inclusion_of :is_active, :in => [true, false]
end
在控制器中,我有可能会返回一个活跃的功能问题(如果有的话)
def get_active_question
begin
@question = Question.active.first
end
end
我试图与rescue_from ActiveRecord::RecordNotFound, with: :no_record_error
,但这似乎没有影响
如何在未返回活动问题时捕捉/解救异常? (我想提出另一种观点)。非常感谢