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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:47:18+00:00 2026-05-23T19:47:18+00:00

Rails 3.1 Devise 1.4.2 I’ve added first_name and last_name columns to devise’s User table.

  • 0

Rails 3.1
Devise 1.4.2

I’ve added first_name and last_name columns to devise’s User table.
Then I’ve used to console to add a first_name and last_name for my first user.

Now, my application.html.erb displays my first name and last name thanks to the following code after I’ve made sure the user is logged in:

<%= current_user.first_name %> <%= current_user.last_name %>(<%= current_user.email %>)

Here’s my problem: when I try to register a new user via the new user form I’ve created, the first_name and last_name are not stored in the database or something… because when I log in with the new user the code I have on my application.html.erb does not display the first and last name.

Here’s the text fields for the first and last name in the new.html.erb:

<p><%= f.label :first_name %><br />
   <%= f.text_field :first_name %></p>

<p><%= f.label :last_name %><br />
   <%= f.text_field :last_name %></p>

<p><%= f.label :email %><br />
   <%= f.email_field :email %></p>

I’d also like to know how to add validation for these new columns I’ve created (first_name and last_name).

Thanks in advance!

  • 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-23T19:47:19+00:00Added an answer on May 23, 2026 at 7:47 pm

    Rails 3

    By default, devise makes all attributes protected. For any attribute you want to be able to mass assign (e.g via a form), you need to explicitly allow it in your model:

    attr_accessible :first_name, :last_name
    

    It worked in your console because you probably did something like this:

    @user = User.first
    @user.first_name = "foo"
    @user.save
    

    But this won’t work if the attribute is not accessible:

    @user = User.new(:first_name => "foo")
    @user.save
    

    You’ll should see a warning "Can’t mass assign protected attributes" in your log file.

    For validations, check out the Rails docs or this guide. For example, to ensure a full name is provided, add

    validates_presence_of :first_name, :last_name
    

    to your model.

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

Sidebar

Related Questions

In rails devise when I set up a user, then delete him, then recreate
I'm using rails 3 with devise. I have a User table with fields: email,
I'm using rails 3.1.3 and devise 1.5.3 and when I add destroy_user_session_path to my
I am using rails 3.2 and devise 1.5.3. I added an admin attribute in
I recently added devise confirmable module to my rails app. My application runs well
I installed devise successfully: @ubuntu:~/boltzman$ rails generate devise User invoke active_record create db/migrate/20111109080820_devise_create_users.rb create
I'm using Rails 3 with Devise for user auth. Let's say I have a
I have a Rails 3 App using devise. I want to create a User/Profile
I am using Devise in Rails 3, and have a User model in rails
in rails 3 devise, a user record has an encrypted_password and a password_salt. How

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.