Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

User Authentication with Rails

Can someone help me out with this "Creating a Sessions Controller" quiz question?

Type the method that we would call on the user object to check the submitted password:

user = User.find_by(email: params[:email]) if user && user._______________________

My answer:

user = User.find_by(email: params[:email]) if user && user.authenticate(params[:password])

Thanks!

6 Answers

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey all, the correct answer is authenticate since that is the name of the method. It's a little tricky but we aren't asking for the parameters to the method.

David Curtis
David Curtis
11,301 Points

Try this:

if user && user.authenticate(params[:session][:password])

Stone Preston
Stone Preston
42,016 Points

that doesnt seem to be working either.

Stone Preston
Stone Preston
42,016 Points

The code snippet from this video suggests your answer is correct.

here is the snippet:

user = User.find(params[:email])
if user && user.authenticate(params[:password])
  session[:user_id] = user.id
  redirect_to todo_lists_path
else
  flash.now[:error] = "There was a problem authenticating."
  render action: 'new'
end

any thoughts Jason Seifer ?

Stone Preston
Stone Preston
42,016 Points

Hmm that looks correct. Can you post a link to the quiz?

Mystery solved! Thanks a lot everyone.