我正在尝试使用查询重写功能在模型级别使用声明性授权来过滤 html 选择选项,如下所示:
模型:
class TreatmentClinic < ActiveRecord::Base
def self.filtered_by_user_context
with_permissions_to(:read)
end
end
查看(新动作):
<%= form_for(@something) do |f| %>
<%= f.select :id, TreatmentClinic.filtered_by_user_context.collect {|t| [ t.name, t.id ] }, {:include_blank => 'Please select'} %>
<%= f.submit %>
<% end %>
授权角色.rb:
role :some_role do
has_permission_on :treatment_clinics do
to :read
if_attribute :id => '1'
end
end
我正在使用巫术,并让它与声明性授权很好地配合使用;声明性授权权限在控制器和视图级别工作正常,但上面的选择抛出此错误:
No matching rules found for [:read] for #<Authorization::AnonymousUser:0x007fd257c00090 @role_symbols=[:guest]> (roles [:guest], privileges [:read, :manage], context :treatment_clinics).
有任何想法吗?