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

  • Home
  • SEARCH
  • 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 7557971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:16:17+00:00 2026-05-30T12:16:17+00:00

When editing a basic User model in Rails from the edit.html.erb form, I would

  • 0

When editing a basic User model in Rails from the edit.html.erb form, I would like to apply special logic if the User’s email address is changed. I am having trouble trying to setup the IF statement in the controller.

Here is what I have in the Users Controller:

class UsersController < ApplicationController
    .
    .
    .
    def edit
        @user = User.find(params[:id])
    end

    def update
        current_email = @user.email
        new_email = params[:user][:email]
        if new_email = current_email
            #update user as usual
        else
            #send email to new email address to confirm
        end
    end
    .
    .
end

When debugging, I find that lines 1 and 2 of the Update action are working correctly. Specifically, when I change the email on the edit User form, the variables are set correctly. But the IF statement (line 3 in the Update action) always seems to return true.

Here is the edit.html.erb form that I am using:

<%= form_for(@user) do |f| %>

    <%= render 'shared/error_messages', :object => f.object %>

    <%= f.label :first_name %><br />
    <%= f.text_field :first_name %><br />
    <%= f.label :last_name %><br />
    <%= f.text_field :last_name %><br />
    <%= f.label :email %><br />
    <%= f.text_field :email %><br />    
    <%= f.label :password %><br />
    <%= f.password_field :password %><br />
    <%= f.label :password_confirmation, "Confirmation" %><br />
    <%= f.password_field :password_confirmation %><br />

<%= f.submit "Update" %>

Any help with this will be greatly appreciated.

  • 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-30T12:16:18+00:00Added an answer on May 30, 2026 at 12:16 pm

    The evaluation operator is == not =. It should read:

    if new_email == current_email
        #update user as usual
    else
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn Django and I would like feedback from anyone who has
I have a Rails form that is being used for creating and editing a
I need some basic CMS functionality with rich text editing. On stack overflow there
When editing HTML in emacs, is there a way to automatically pretty-format a blob
While editing .scm files it would be great if Vim would automatically put the
I am looking for a good pattern for performing basic property editing via a
I am implementing a really basic server-client model in Java, by using UDP sockets
Apple's documentation on UITableView discusses how to add/edit/delete rows, but it doesn't discuss adding/editing/deleting
I have an app where I need to prevent users from editing data while
I just started diving into vi and so far learned only basic moving around/editing

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.