ruby on rails - How to set additional variables upon form submit, based on value of one of the submitted fields? -
i have form , upon create save additional variables not included in form itself. therefore in create method have line params[:invitation][:person_two_id] = @person_two.id (see below). calling line before .save thought include person_two_id when saving invitation. however, not case. debugger (see code below placed debugger) shows:
params[:invitation][:person_two_id]101@invitationhasnilvalueperson_two_id:#<invitation id: 171, person_one_id: nil, person_two_id: nil, organization_id: 87, email: "example@example.com", message: "dsfsd", created_at: "2015-07-07 14:36:35", updated_at: "2015-07-07 14:36:35">
hence, when saving @invitation, has not automatically saved person_two_id value @invitation. why not? should differently?
my controller method:
def create @invitation = invitation.new(new_params) @person_two = user.find_by(email: params[:invitation][:email].downcase) params[:invitation][:person_two_id] = @person_two.id @invitation.save debugger invitationmailer.invitation(@invitation).deliver_now end
i needed replace params[:invitation][:person_two_id] = @person_two.id @invitation.person_two_id = @person_two.id , worked.
Comments
Post a Comment