我试图在完成表单后手动向控制器中的参数添加其他属性。参数似乎包裹在中,这似乎阻止了我更改参数。
控制器:
class ActualsController < SignedInController
...
def update
respond_to do |format|
facesheet = actual_params[:facesheet]
#trying to manually add attribute
actual_params.merge(:file_name => 'ted.png')
new_params = actual_params.except(:facesheet)
if @actual.update(new_params)
format.html { redirect_to action: 'show', id:@actual.id, notice: 'Actual was successfully updated.' }
format.json { render :show, status: :ok, location: @actual }
else
format.html { render :edit }
format.json { render json: @actual.errors, status: :unprocessable_entity }
end
end
end
...
end
Run Code Online (Sandbox Code Playgroud)
控制台中的“ new_params”
<ActionController::Parameters {"encounter_type_id"=>"1", "physician_id"=>"669", "insurance_id"=>"1182", "time_start"=>"05:00", "time_end"=>"07:00", "date_start"=>"2017-08-02", "date_end"=>"2017-08-02", "facility_id"=>"1", "med_rec_num"=>"1244", …Run Code Online (Sandbox Code Playgroud)