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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:43:20+00:00 2026-05-18T20:43:20+00:00

i am new to Rails .. i am having a Table named users (id,name)

  • 0

i am new to Rails ..
i am having a Table named users (id,name)
and another table which has the additional information of the user called
user_details(id,user_id,additional_info) where additional_info is a hash .

In the User Model i added a line

has_one :user_details

And in the User_Detail model i added a line

belongs_to :user
serialize :additional_details, Hash

Now in the Users Controller i am having an action

# set_user_empid to set the hash value empid in the additional_info column for the current_user
    def set_user_empid  
           @user1 = current_user
           @user_detail1=@user1.user_details
           @user_detail1.additional_details[:empid] = params[:value]
           @user_detail1.save
           render :text => CGI::escapeHTML(@user_detail1.additional_details[:empid].to_s)

    end 

The above one @user1.user_details shows me the error as

NameError (uninitialized constant User::UserDetails):

But the same thing if i change the has_one to has_many i am getting the actual result…

Please give suggestions…

  • 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-18T20:43:20+00:00Added an answer on May 18, 2026 at 8:43 pm

    The quick fix here is to change has_one :user_details to has_one :user_detail, but really what you want is to get rid of the UserDetail model entirely and just move the column into the User model, so the users table has these columns: id, name, additional_info and then move the call to serialize into the User model. No real reason to have a separate table just for metadata.

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

Sidebar

Related Questions

I am having trouble accessing the correct information in my rails model (which I
I am having a ruby on rails application.I added a new section called reports
i am very new to rails . I am having a table holding all
I've got the following User model: class User < ActiveRecord::Base # Users table has
I'm new to rails and I'm having some trouble in the console. I'd like
I'm developing a new rails application which is supposed to be installed several times
I am working on a new rails 3.2 company management app which relies heavily
I'm new to rails and having trouble figuring out how to do this RESTfully.
I'm creating a new web application (Rails 3 beta), of which pieces of it
I'm new to rails after moving from PHP and am having no end to

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.