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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:24:04+00:00 2026-05-27T00:24:04+00:00

I have a very simple user model. When I first created it, it had

  • 0

I have a very simple user model. When I first created it, it had three fields email, password_hash, and password_salt.

I recently added a field to that model, in order to allow the user to set a display name, the field being called display. I used the method as outlined in this answer. So what I typed into terminal would look like this:

script/rails g migration add_display_to_users display:string

and then

rake db:migrate

This worked fine, and after modifying my signup form, I was able to add this data into the database.

In my application layout, I then want to display the user’s display name in the header. So, in my application controller, there is a method I call in every controller in order to get the nav bar, called nav_bar. In this method I also set a @user instance variable, if they are logged in.

Because the nav_bar method is called in the application controller, I can then access it from the application layout. So, I tried to show their email in the header as a test, like so:

<% if @user %>
    <div class="ac_button">
        <%= @user.email %>
    </div>
<% end %>

This works fine, and displays their email in the header. However, if I change it to

 <%= @user.display %>

It doesn’t display anything.

The strangest part, is if I call @user.email, or any other property of the user somewhere in my application controller or layout. It works, and shows their display name. I have no idea why that would make it work, but it does.

For example, if after finding the user in the application controller, I call @user.email, it will then show their display name in the layout fine.

def nav_bar
    if session[:user_id]
      @user = User.find(session[:user_id])
      @user.email
    end
    # create and return the navbar
end

Or if in the layout, I call a property of the user anywhere, it also works.

<div class="ac_button">
    <% @user.password_hash %>
    <%= @user.display %>
</div>

If anyone can explain this very strange behavior I will be amazed!

  • 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-27T00:24:04+00:00Added an answer on May 27, 2026 at 12:24 am

    The name display is an inherited method from ActiveRecord::Base so when you create a column called display the method displayand display= are created. So you overweite an ActiveRecord method by creating the column display. Had this problem earlier,… renamed the column to display_name and everything was fine! 😉

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

Sidebar

Related Questions

I have a very simple issue: User model: class User < ActiveRecord::Base devise :database_authenticatable,
I have a very simple rails 3 program with 2 models: a user model
This is driving me crazy. I have a very simple user control: public int?
I have a very simple page with which a user uploads a file. Using
i have very simple problem. I need to create model, that represent element of
I've got a very simple Rails 3 app with a User model run by
I have a very simple method: Class Team(models.Model): def sides(self): return SideNames.objects.filter(team=self) SideNames is
I have created a very simple ASP.NET HttpHandler and for some reason it is
I have a very simple bit of jQuery to retrieve my latest Tweet $.getJSON(http://twitter.com/statuses/user_timeline/username.json?count=1,
I have very simple select like this: SELECT * FROM table WHERE column1 IN

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.