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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:30:14+00:00 2026-06-16T00:30:14+00:00

I am having a terrible time understanding the assignment function that is needed, as

  • 0

I am having a terrible time understanding the assignment function that is needed, as explained in chapter 8.2.3. of the Hartl’s tutorial.

As context, he is focused on the second line of the following sign_in function:

  def sign_in(user)
    cookies.permanent[:remember_token] = user.remember_token
    self.current_user = user #<-- this line
  end

Where he mentions because its an assignment, it must be then separately defined as

def current_user=(user)
    @current_user = user
end

Where the method current_user= expressly designed to handle assignment to current_user. My confusions is:

  1. Why is this even necessary? I thought that a simple = would allow you to assign things. For example user.email = hello@kitty.com

  2. Also, when eventually he will code redirect_to current_user, how does something that belongs to the SessionsController get translated to a view controlled by UsersController?

Thanks!!

  • 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-06-16T00:30:15+00:00Added an answer on June 16, 2026 at 12:30 am

    The reason being it is needed as to avoid confusion (for the interpreter/VM) between method invocation and variable assignment

    def foo
      # Two completely different things!
      bar = "baz" # assigns baz to local variable bar
      self.bar = "baz" # invokes the bar= method with parameter of baz
    end
    

    What’s happening there is that he is doing two things, firstly invoking the current_user= method with the user object and secondly, setting that to @current_user (it’s not a great example – you’d probably end up doing a lot more in real life if you were to make a current_user= method such as setting up session variables).

    secondly redirect_to current_user is equivalent to redirect_to user_path(current_user) – check out http://api.rubyonrails.org/classes/ActionController/Redirecting.html for more details which explains the different parameter kinds that redirect_to can take. Note this is a redirect, not a render – so a second HTTP request happens here.

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

Sidebar

Related Questions

I am having a terrible time understanding how to get the wrapper to work
I am having a terrible time trying to do something that should be easy.
I am having a terrible time figuring this one out. I have a form.
I am having a terrible time trying to get an input box like the
I'm having a difficult time understanding how to get Rails to show an explicit
I have been having a terrible time trying to compile a python extension -
I'm having a terrible time trying to pull out some values out of an
My title is terrible but I'm having a hard time wrapping my head around
I'm having a terrible time convincing myself what I've done here is a good
I am having a terrible time getting my height of my DIVs to properly

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.