How do I explicitely call Devise sign_in? I already have a method in my controller called sign_in
.
I tried
require 'devise/controllers/sign_in_out'
Devise::Controllers::SignInOut.sign_in @user
cannot load such file -- devise/controllers/sign_in_out
and
include Devise::Controllers::Helpers
Devise::Controllers::Helpers.sign_in @user
undefined method `sign_in' for Devise::Controllers::Helpers:Module
but neither worked.
I also tried
alias_method :devise_sign_in, :sign_in # keep hold of the Devise sign_in method before we overwrite it.
devise_sign_in @user
which worked in the browser but when I ran rspec
it gave this error:
/rsync/BK-Development/app/controllers/community_members_controller.rb:5:in
alias_method': undefined method
sign_in' for classCommunityMembersController' (NameError) from /rsync/BK-Development/app/controllers/community_members_controller.rb:5:in
'
I found the source of the method here:
https://github.com/plataformatec/devise/blob/v2.2/lib/devise/controllers/helpers.rb
Devise version 2.2.8
Ok I got it to work with
include Devise::Controllers::Helpers
alias_method :devise_sign_in, :sign_in # keep hold of the Devise sign_in method before we overwrite it.
...
devise_sign_in @user
I'd still like to know how to call a method directly. In Java, you can call any method by specifying the full package and method. There should be a way to do that in Ruby too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With