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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:16:17+00:00 2026-06-01T23:16:17+00:00

I don’t understand why I get a nil error below. But when I add

  • 0

I don’t understand why I get a nil error below. But when I add self I don’t get the error and everything gets assigned corrected. Can you explain to me why if I don’t use self this does not work?

models/user.rb

def update_user_email!(new_email)
  email = new_email # When I use self.name = new_email this works
end

controllers/users_controller

def create
  @user = User.new(params[:user])
  @user.update_user_email!(email)
  @user.save
end

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-01T23:16:18+00:00Added an answer on June 1, 2026 at 11:16 pm

    When you are in a method inside a model, if you use just the attribute name it will treat it like a variable with the scope limited to this method. Using self.attribute will actually access the underlying field in the model and let you assign values.

    As a basic rule, any time you are actually assigning values in a model, you should always use

    self.attribute = value
    

    On a side point, I am not sure if your code was for example only, but it doesn’t like look a method you would need.

    In the controller you could just do

    @user.email = email
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know how to explain it better but i'm trying to get a response
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't ask why, but is there any way to suppress a failed linking error?
Don't know what to do with this error. How to add data in SQL
Don't ask me how but I managed to get accidentally the following remote branches
Don't get me wrong, I want them to get saved. But I always thought
Don't get me wrong - I love Smalltalk, but... To me, the Squeak interface
Don't ask me why but i can't use this method because I need to
Don't know why but I can't find a solution to this. I have 3
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,

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.