我有default_scope的模型:
class Campaign < ActiveRecord::Base
default_scope where("campaigns.status != ?", "archive")
end
然后我需要在show action中禁用此范围:
@campaign = Campaign.unscoped.find(params[:id])
但我看到Couldn't find Campaign with id=1 [WHERE (campaigns.status != 'archive')]
然后我在rails console中尝试了相同的解决方案:
Campaign.unscoped.find(1)
SELECT `campaigns`.* FROM `campaigns` WHERE `campaigns`.`id` = 1 LIMIT 1
一切正常,我在控制器中做错了什么?
更新
Campaign.unscoped { }
也没用。似乎@campaign在其他地方和之前确定过,因为我删除了show动作中的所有行,现在它看起来像:
def show
end
我仍然收到此错误:Couldn't find Campaign with id=1 [WHERE (campaigns.status != 'archive')]
我在load_and_authorize_resource
中找到了这个技巧,但我该如何解决呢?