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…
The quick fix here is to change
has_one :user_detailstohas_one :user_detail, but really what you want is to get rid of the UserDetail model entirely and just move the column into theUsermodel, so the users table has these columns:id,name,additional_infoand then move the call toserializeinto theUsermodel. No real reason to have a separate table just for metadata.