ruby - Merge method issue rails -
background: have model called opportunity has "created_by" , "team_name" attributes, correspond user model has "full_name" , "team" attribute. thus, when user logs in , creates new opportunity record, systems created_by = user.full_name.
problem (except opportunity controller):
def create @opportunity = opportunity.new(opportunity_params) @opportunity = opportunity.new(opportunity_params.merge(:created_by => current_user.full_name)) @opportunity = opportunity.new(opportunity_params.merge(:team => current_user.team)) end
i use opportunity_params.merge method twice. when happens, last opportunity_params.merge line works. right now, use opportunity_params.merge record current_user.team current_user.full_name not record. can help?
merge changes before use params:
merged_opportunity_params = opportunity_params.merge( created_by: current_user.full_name, team: current_user.team ) @opportunity = opportunity.new(merged_opportunity_params)
Comments
Post a Comment