Access getCan parameters in CanCan

Can I access the parameters passed in the url in CanCan? I am trying to authenticate guests based on a token in the url.

Thank!

+3
source share
2 answers

I recently achieved something similar using the method described here:

https://github.com/ryanb/cancan/wiki/Accessing-request-data

In my case, it looked something like this:

application / controllers / application_controller.rb:

class ApplicationController < ActionController::Base

  ...

  def current_ability
    @current_ability ||= Ability.new(current_user, params[:token])
  end

end

application / models / ability.rb:

class Ability
  include CanCan::Ability

  def initialize(user, token=nil)
    ...
    can :read, Article, :tokens => { :token => token }
    ...
  end

end
+5
source

We are currently using something similar to authorize! action, resource, session[:access_token]the front filter - from this page: http://spreecommerce.com/documentation/security.html

+2
source

All Articles