开发者

overwrite authenticate_user! in devise gem

开发者 https://www.devze.com 2023-04-13 08:56 出处:网络
I\'m overwriting my au开发者_如何学JAVAthenticate method in my application controller def authenticate_worker!

I'm overwriting my au开发者_如何学JAVAthenticate method in my application controller

def authenticate_worker!
  if user_signed_in? && current_user.worker?
    authenticate_user!
  else
    super
  end
end 

I keep getting

wrong number of arguments (1 for 0)
app/controllers/application_controller.rb:51:in `authenticate_worker!'

Any idea what i'm missing? Thanks!


I had the same problem and fixed it doing this:

class ApplicationController < ActionController::Base
  protected
  def authenticate_user!(opts={}) 
    opts[:scope] = :user
    warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
    flash[:alert] = "I always have to monkeypatch devise... because I'm lazy to use the sorcery gem."
  end
end

So, wrapping. up, copy and paste the code above and substitute flash[:alert] with what you want to do after you are sure the user is authenticated.

The wrong number of arguments (1 for 0) error happens because of the opts optional parameter.


found it. It was passing {:force=>true} Not sure what that argument does though...

0

精彩评论

暂无评论...
验证码 换一张
取 消