mercredi 14 novembre 2018

Unable to save/update the record into db in rails

I am trying the update the record for the columns IsValid and Comments in rails, but doesn't get updated in backend or any error:

Below is my parameters result:

Started PATCH "/metrics/1" for 
Processing by MetricsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"1oC/1UdAaTPUepy1zIjO1x6n67Th/pdcnvYJH95cB63tZts9d135JIK4MzQD2/pdPoRKnUKXIc0ZI9MQZkjfNQ==", 
  "metrics_controller"=>{"IsValid"=>"False", "Comments"=>"1"}, "commit"=>"Save", "id"=>"1"}
  Metric Load (75.1ms)  SELECT  `Threshold`.* FROM `Threshold` WHERE `Threshold`.`ID` = 1 LIMIT 1
Unpermitted parameters: utf8, _method, authenticity_token, metrics_controller, commit, id
   (75.7ms)  BEGIN
   (75.1ms)  COMMIT

enter image description here

update method in controller:

 def update
        @metric = Metric.find(params[:id])
        #if(@metric.update(post_params))
        if(@metric.update_attributes(post_params))
          redirect_to metrics_path
        else
          render 'edit'
        end
      end
       private def post_params
    params.permit(:Metric, :WI, :Value, :UT, :Score, :IsValid, :UserName, :Comments)
  end

If I update post_params method with the below code it is throwing error:

private def post_params
    params.require(:metric).permit(:Metric, :WI, :Value, :UT, :Score, :IsValid, :UserName, :Comments)
  end

Aucun commentaire:

Enregistrer un commentaire