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 7515151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:42:51+00:00 2026-05-30T00:42:51+00:00

When I omitted ‘self.’ from the method definition, Rails couldn’t find a method. undefined

  • 0

When I omitted ‘self.’ from the method definition, Rails couldn’t find a method.

undefined method `authenticate' for #<Class:0x00000103b8c640>
...
app/controllers/sessions_controller.rb:6:in `create'

Here is the snippet from the source,

class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation

attr_accessor :password

before_save :encrypt_password
...
def encrypt_password
  if password.present?
    self.password_salt = BCrypt::Engine.generate_salt
    self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
  end
end

def authenticate(email, password)
  user = find_by_email(email)
  if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
    user
  else
    nil
  end
end

and authenticate() is called from SessionController

class SessionConstroller < ApplicationController

def create
  user = User.authenticate(params[:email], params[:password])
  ...
end

When I add ‘self.’ to the definition of authenticate(), it works without error.

What’s the difference between adding ‘self.’ and nothing to the method definition in Rails 3.x?

self.authenticate(...)

authenticate(...)
  • 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-30T00:42:52+00:00Added an answer on May 30, 2026 at 12:42 am

    Adding self to the method definition makes it a class method rather than an instance method. So when you try and call User.authenticate, it only works if you defined the method on the class rather than for instances of User.

    Like this:

    class User
      puts self.inspect   # would return "User"
    
      def self.authenticate
        puts self.inspect  # also returns "User" when called like User.authenticate
      end
    
      def authenticate
        puts self   # will only work for instances of User.
      end
    end
    

    Try playing around with small example codes like this, rather than straight away within the larger context.

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

Sidebar

Related Questions

(This is not an interface: I simply omitted the method bodies) class _ {
Given the following entity (some columns omitted from this long definition for brevity): @Table(name
Do you bother initialising java bean values? Say, for example: ([g|s]etters omitted) public class
Consider the following code: class Foo { // boring parts omitted private TcpClient socket;
Imagine the following template class (setter and getter for the member _t omitted): template<class
The issue: When readin CDATA elements, carriage return (0xD) are omitted from the output.
I have a Rails log that looks like this Started GET [path-omitted] for 166.137.138.210
I have this SQL with UNION. The FROM part is omitted. This SQL generates
I have a table that has structure like this (td omitted) <table> <tr class=header>...</tr>
Consider: /* bar.h */ class bar{ /* Standard stuff omitted */ std::vector<my_obj*> foo; };

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.