update after delete row in ruby on rails -
two models have created i.e "user" , "communication", , schema below:
user model scheme: id | name | email | skilltype | user_need 1 | ijk | ijk@ijk.com | mentor | ap chinese 2 | mno | mno@mno.com | protege | ap biology communication model schema: id | userid | communicationmode | communicationdetail 1 | 1 | phone | 1234567890 2 | 1 | email | ijk@ijk.com
in user model have has_many
relation communication, , in communication model have belongs_to :user
adding communication preferences when user sign ups application, , in setting, trying display user's communication preferences in separate controls.when user submits settings page, want delete each record in communication related current_user, working fine , code below
communication.delete_all(:userid => current_user.id)
but when update them new action in controller, records not updating communication. , below "new" action code:
def create @user_basic=user.find(current_user.id) @students=students.all @entrepreneurs=entrepreneurs.all @veterans=veterans.all @user_communication=communication.where(:userid => current_user.id) communication.delete_all(:userid => current_user.id) @user_communication.update_attributes(:communicationmode => "communicationdetail") render 'new' end
and getting below error @ line '@user_communication.update_attributes(:communicationmode => "communicationdetail")'
error: undefined method `update_attributes'
kindly suggest me make mistake, waiting reply. thanks
i don't trying do,
@user_communication=communication.where(:userid => current_user.id) communication.delete_all(:userid => current_user.id) @user_communication.update_attributes(:communicationmode => "communicationdetail")
you delete communications given user , try update attributes communicationmode = "communicationdetail"
.
so, update fails because there no record. sure there problem logic try apply.
Comments
Post a Comment