4

私は可能な限りあらゆる方法を試しましたが、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メソッドを使用しようとすると、undefinedエラーが発生します。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メソッドにアクセスする方法はありますか?それは私がそれを必要としていた他のどこでも機能します。

4

1 に答える 1

3

メソッドへのアクセスは、active_admin 内の application_controller 内のものであっても、しばしば苦痛を伴う場合があります。

しかし、コントローラーを明示的に書き直すことで完全にスキップできます。理想的ではありませんが、機能します。

 controller do 
  #  authorize_resource
    def index
      if can? :manage, :all
        @bookings = Booking.page params[:page] #you must call .page for the index to work.
      else
        @bookings = current_user.bookings.page params[:page]
      end
      index! #this is needed unless you are using custom views
    end 
  end
于 2011-11-09T10:22:15.613 に答える