制定Rails中无作用域的授权 [英] Devise unscoped authorization in Rails
本文介绍了制定Rails中无作用域的授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个模型:
class Engineer < ActiveRecord::Base
default_scope { is_published }
scope :is_published, -> { where(is_published: true) }
end
工程师可以通过GitHub的网站上的授权。我想给授权的网站未发表的工程师太上的能力。在某些控制器有这样的过滤器:
Engineers can be authorized on the site via GitHub. And I want to give ability to authorize on the site for unpublished Engineers too. There are such filters in some controllers:
before_action :authenticate_engineer!, only: [:show]
但是,现在全成授权工程师后,仍然无法通过这些过滤器。怎么说设计他应该无作用域的工程师之间的搜索?想想,我应该重写一些设计方法...
But now after successfull authorization Engineer still can't pass these filters. How to say Devise that he should search between unscoped Engineers? Think, I should override some Devise method...
推荐答案
解决办法是覆盖在Engineer.rb这种设计方法:
Solution was to override this Devise method in the Engineer.rb:
def self.serialize_from_session(key, salt)
Engineer.unscoped {super}
end
这篇关于制定Rails中无作用域的授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文