Suggestions on moving the existing users to a new table in rails
I am having a Users Table (id,name) and another table User_detail(id,user_id,additional_details) where additional_details is a hash
i have added the user_detail table just now as an extension of my application. the logic i have used is ,
Once the user signs up -- a default entry will be made in the User detail table with empty values.. (done by having a after_create: set_defaul开发者_运维知识库tvalues) And then inside the app , the user can edit their additional_detail..
But the already existing users are missing in the user detail .
What could be done for them .Please give suggestions..
Why not just:
script/console production
User.all.each{|u| u.set_defaultvalues if u.user_detail.blank?}
If you want to add user_detail
to each user, then why don't you just add new column to users table? Then you don't need another model, another association and you don't have to think about creating child object for every user. You will also save some joins in your queries.
精彩评论