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