我已经尝试了所有可能的方法,但似乎无法使用 cancan 限制 active_admin 中的 scope_to 方法。
我可以让菜单和大多数其他方法一样玩得很好,但不是 scope_to
例如,这很好用:
menu :if => proc{ can?(:manage, Booking) }
但不是
scope_to :current_user, :association_method => :space_bookings unless proc{ can?(:manage, Booking) }
或者
scope_to :current_user, :association_method => :space_bookings unless proc{ current_user.admin? }
或者
scope_to :current_user, :association_method => :space_bookings unless controller.current_ability.can?( :manage, config.resource )
如果我尝试在没有 proc 的情况下使用 current_user 方法,则会收到未定义的错误。current_user 方法由 devise 和 active_admin.rb 定义
# == Current User
#
# Active Admin will associate actions with the current
# user performing them.
#
# This setting changes the method which Active Admin calls
# to return the currently logged in user.
config.current_user_method = :current_user
有什么想法可以访问 current_user 方法吗?它适用于我需要它的其他任何地方。