0
votes

i have a simple controller where i want to log user manually and for some reason devise method sign_in is not working

Here is my controller:

class Brand::ChallengesController < ApplicationController

 def sign_in
  user = User.find_by_email(params[:email])
  if user and user.valid_password?(params[:password])
    sign_in(:user, user)
    redirect_to brand_challenges_url
  else
    ...
  end
end
...

edit : I always get this answer on the sign_in method:

wrong number of arguments (2 for 0)

It seems that i only can use this method within a devise child class. I tried to include many Devise helpers but nothing it working for the moment.

1
Hi - where are you getting the error? can you give us the full stacktrace (especially the exact line-number that is causing the error) - Taryn East

1 Answers

1
votes
def sign_in
  user = User.find_by_email(params[:email])
  if user and user.valid_password?(params[:password])
    sign_in(:user, user)
    ^^^^^^^

See that line. You are calling sign_in - which is the name of method that you just wrote. Which means your code is calling itself... and your sign_in method has zero parameters.

(If you took away the (:user, user) part... you'd actually get a stack overflow - because your code would call itself... which would call itself... over and over until the memory just exploded and died).

Are you trying to call some other method called sign_in ? if so - where is that method located?