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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:37:03+00:00 2026-05-20T21:37:03+00:00

I am currently working through http://ruby.railstutorial.org/chapters/sign-in-sign-out#sec:current_use r] 1 and I am having trouble understanding

  • 0

I am currently working through http://ruby.railstutorial.org/chapters/sign-in-sign-out#sec:current_user]1 and I am having trouble understanding what the difference between the two current_user methods. In my other method sign_in there is a called to self.current_user but I am having trouble understanding which current_user is called and what the other current_user method is actually doing.

module SessionsHelper
  def sign_in(user)
    cookies.permanent.signed[:remember_token] = [user.id, user.salt]
    self.current_user = user
  end

  def current_user=(user)
    @current_user = user
  end

  def current_user
    @current_user ||= user_from_remember_token
  end

  def signed_in?
    !current_user.nil?
  end

  private
    def user_from_remember_token
      # using the * makes us pass two values [id,salt]
      User.authenticate_with_salt(*remember_token)
    end

    def remember_token
      cookies.signed[:remember_token] || [nil,nil]
    end
end
  • 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-20T21:37:04+00:00Added an answer on May 20, 2026 at 9:37 pm

    The current_user= method is called when you assign to the current_user attribute of your object, and the current_user method is called when you don’t.

    So self.current_user = user calls current_user= while !current_user.nil? calls current_user.

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

Sidebar

Related Questions

I'm currently going through a RoR tutorial ( http://railstutorial.org/chapters/sign-in-sign-out#sec:signin_success is the relevant section) which
I'm working through Michael Hartl's Ruby on Rails tutorial on http://ruby.railstutorial.org . I'm having
I'm working through http://railstutorial.org (currently working on section 10.4.2 - destroying users). My User
I'm currently working my way through http://www.railstutorial.org/ It uses Rspec along with a TDD
I'm currently working on this site … http://bit.ly/yR6xzta When scrolling through the site or
I'm currently working my way through this book: http://www1.idc.ac.il/tecs/ I'm currently on a section
I am following the Ruby on Rails tutorial by Michael Hartl http://ruby.railstutorial.org/ I installed
So I'm just getting started with Python, and currently working my way through http://diveintopython3.ep.io/
I'm currently trying to return msgpack http://msgpack.org/ from a ruby sinatra service and parse
I am currently working through this tutorial: Getting Started with jQuery For the two

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.