Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5960261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:48:07+00:00 2026-05-22T18:48:07+00:00

Controller Call user = User.authenticate(params[:session][:email], params[:session][:password]) Authenticate Method in user.rb class << self def

  • 0

Controller Call

user = User.authenticate(params[:session][:email],
                         params[:session][:password])

Authenticate Method in user.rb

class << self
   def authenticate(email, submitted_password)
      user = find_by_email(email)
      user && user.has_password?(submitted_password) ? user : nil
      #return nil if user.nil?
      #return user if user.has_password?(submitted_password)
   end
end

I’ve been looking at some example rails code and I’m a little confused by this. I understand that it’s calling the authenticate method on the user object and then sending in an email and password values, but what is the :session symbol for? I look all through the code to find it, but I can’t seem to figure it out. I don’t see a method named session or anything.

Also, when the user actually uses the program, they only give a value for email and password, nothing for session. Not really sure what it’s doing.

I’m asking this because it seems like some “rails general practice” type of thing. However I might be wrong and am not providing enough information. Please let me know if I have not.

Lastly, the Class << self, that is just there to define that the User object is being created in that class correct?

Thanks for the help in advance! (Also I know the moderators are going to edit this to fix my code block, if you guys could tell me what I’m doing wrong and how to fix it, I’d appreciate it!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:48:08+00:00Added an answer on May 22, 2026 at 6:48 pm

    Alright, there’s about 50 different questions there, but let’s see how we go.

    First: the params method returns a list of parameters received by your controller’s action. These are often (99%) sent through by the request, but also can be set by middleware. These two parameters, params[:session][:email] and params[:session][:password]are coming through like that because on the page before hand you’ve defined a text_field like this (I’m guessing):

     <%= text_field "session", "email" %>
    

    The first argument to this method tells Rails what object to operate on, namely a @session (or @user_session) object (which is not the same as the session object you may see in controllers). The second argument gives a special, unique name to this field. In this case, it’s email. Because it’s been defined like this, it will be passed back to the controller as params[:session][:email] and not simply params[:email]. It is done this way so that you can differentiate different fields which may send back similarly named values.

    That should answer what session is. The :session “thing” itself is actually a symbol. If you’ve done some reading about Ruby you would know what they are.

    Finally: the class << self ‘special sauce’ is actually defining a class-level method for the class that it’s in. You could also define this by doing it this way:

    def self.authenticate(arguments)
      # code goes here
    end
    

    Some people prefer class << self as it allows you to group class methods into a big block of them, but others prefer the explicit statement of def self.method (there’s even some who do def SomeClass.method! Don’t listen to them…). It’s up to you what path you choose here.

    Okay, so my estimate of 50 questions was a little off (by 48) but I think this should help you understand some things. If you’re still confused, see a doctor or read a Rails book.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a controller method like: def show @model = Model.find(params[:id]) respond_to do |format| format.html
In my view controller's -viewDidLoad method, I call [myTextField becomeFirstResponder]; This works like a
I have a controller with an action method as follows: public class InventoryController :
on each controller call i have a code that gets some user properties from
I have a controller action which I would like to call another controller action.
When you call RedirectToAction within a controller, it automatically redirects using an HTTP GET.
My Controller class is decorated with an AuthorizeAttribute to protect the actions: [Authorize(Roles =
I want my controller to return the right HTTP response code when the user
I have a controller that makes HTTP GET requests using a custom class, which
So the controller context depends on some asp.net internals. What are some ways to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.