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 @[email protected]_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...

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I just changed the :has_one :user_details to has_one :user_detail and in the Users controller i used like current_user.user_detail and it workz .. THank u
1

I believe since you are using user_details, pluralized, it is not able to pick it up. Could you try using has_one :user_detail

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.