Unable to save/update the record into db in rails










0















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









share|improve this question






















  • You need to leave the post_params method in as it permits the parameters. Can you posy what error message occurs when you try and update please?

    – Mark
    Nov 14 '18 at 13:18












  • I'm not sure, but it looks like your header's params are send as body. How do you call update method? Ajax async call? Html/Rails form? could you update your answer?

    – Pietro Allievi
    Nov 14 '18 at 15:15











  • Hi @Mark , I don't get any error but the data doesn't get saved in db

    – Mallela SriPrakash
    Nov 14 '18 at 15:20






  • 1





    @MallelaSriPrakash replace if(@metric.update_attributes(post_params)) with if(@metric.update_attributes!(post_params)) please, the server will then throw an error and explain what is going wrong

    – Mark
    Nov 14 '18 at 15:21











  • @Mark As you have said, I have replaced it. But still I don't get any error while updating. But, when I changed the text as this if(@metric.update_attributes(!post_params)) then I get this error: When assigning attributes, you must pass a hash as an argument.

    – Mallela SriPrakash
    Nov 14 '18 at 15:45















0















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









share|improve this question






















  • You need to leave the post_params method in as it permits the parameters. Can you posy what error message occurs when you try and update please?

    – Mark
    Nov 14 '18 at 13:18












  • I'm not sure, but it looks like your header's params are send as body. How do you call update method? Ajax async call? Html/Rails form? could you update your answer?

    – Pietro Allievi
    Nov 14 '18 at 15:15











  • Hi @Mark , I don't get any error but the data doesn't get saved in db

    – Mallela SriPrakash
    Nov 14 '18 at 15:20






  • 1





    @MallelaSriPrakash replace if(@metric.update_attributes(post_params)) with if(@metric.update_attributes!(post_params)) please, the server will then throw an error and explain what is going wrong

    – Mark
    Nov 14 '18 at 15:21











  • @Mark As you have said, I have replaced it. But still I don't get any error while updating. But, when I changed the text as this if(@metric.update_attributes(!post_params)) then I get this error: When assigning attributes, you must pass a hash as an argument.

    – Mallela SriPrakash
    Nov 14 '18 at 15:45













0












0








0








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









share|improve this question














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






ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 13:16









Mallela SriPrakashMallela SriPrakash

295




295












  • You need to leave the post_params method in as it permits the parameters. Can you posy what error message occurs when you try and update please?

    – Mark
    Nov 14 '18 at 13:18












  • I'm not sure, but it looks like your header's params are send as body. How do you call update method? Ajax async call? Html/Rails form? could you update your answer?

    – Pietro Allievi
    Nov 14 '18 at 15:15











  • Hi @Mark , I don't get any error but the data doesn't get saved in db

    – Mallela SriPrakash
    Nov 14 '18 at 15:20






  • 1





    @MallelaSriPrakash replace if(@metric.update_attributes(post_params)) with if(@metric.update_attributes!(post_params)) please, the server will then throw an error and explain what is going wrong

    – Mark
    Nov 14 '18 at 15:21











  • @Mark As you have said, I have replaced it. But still I don't get any error while updating. But, when I changed the text as this if(@metric.update_attributes(!post_params)) then I get this error: When assigning attributes, you must pass a hash as an argument.

    – Mallela SriPrakash
    Nov 14 '18 at 15:45

















  • You need to leave the post_params method in as it permits the parameters. Can you posy what error message occurs when you try and update please?

    – Mark
    Nov 14 '18 at 13:18












  • I'm not sure, but it looks like your header's params are send as body. How do you call update method? Ajax async call? Html/Rails form? could you update your answer?

    – Pietro Allievi
    Nov 14 '18 at 15:15











  • Hi @Mark , I don't get any error but the data doesn't get saved in db

    – Mallela SriPrakash
    Nov 14 '18 at 15:20






  • 1





    @MallelaSriPrakash replace if(@metric.update_attributes(post_params)) with if(@metric.update_attributes!(post_params)) please, the server will then throw an error and explain what is going wrong

    – Mark
    Nov 14 '18 at 15:21











  • @Mark As you have said, I have replaced it. But still I don't get any error while updating. But, when I changed the text as this if(@metric.update_attributes(!post_params)) then I get this error: When assigning attributes, you must pass a hash as an argument.

    – Mallela SriPrakash
    Nov 14 '18 at 15:45
















You need to leave the post_params method in as it permits the parameters. Can you posy what error message occurs when you try and update please?

– Mark
Nov 14 '18 at 13:18






You need to leave the post_params method in as it permits the parameters. Can you posy what error message occurs when you try and update please?

– Mark
Nov 14 '18 at 13:18














I'm not sure, but it looks like your header's params are send as body. How do you call update method? Ajax async call? Html/Rails form? could you update your answer?

– Pietro Allievi
Nov 14 '18 at 15:15





I'm not sure, but it looks like your header's params are send as body. How do you call update method? Ajax async call? Html/Rails form? could you update your answer?

– Pietro Allievi
Nov 14 '18 at 15:15













Hi @Mark , I don't get any error but the data doesn't get saved in db

– Mallela SriPrakash
Nov 14 '18 at 15:20





Hi @Mark , I don't get any error but the data doesn't get saved in db

– Mallela SriPrakash
Nov 14 '18 at 15:20




1




1





@MallelaSriPrakash replace if(@metric.update_attributes(post_params)) with if(@metric.update_attributes!(post_params)) please, the server will then throw an error and explain what is going wrong

– Mark
Nov 14 '18 at 15:21





@MallelaSriPrakash replace if(@metric.update_attributes(post_params)) with if(@metric.update_attributes!(post_params)) please, the server will then throw an error and explain what is going wrong

– Mark
Nov 14 '18 at 15:21













@Mark As you have said, I have replaced it. But still I don't get any error while updating. But, when I changed the text as this if(@metric.update_attributes(!post_params)) then I get this error: When assigning attributes, you must pass a hash as an argument.

– Mallela SriPrakash
Nov 14 '18 at 15:45





@Mark As you have said, I have replaced it. But still I don't get any error while updating. But, when I changed the text as this if(@metric.update_attributes(!post_params)) then I get this error: When assigning attributes, you must pass a hash as an argument.

– Mallela SriPrakash
Nov 14 '18 at 15:45












3 Answers
3






active

oldest

votes


















1














The params that are coming from the request (from the logs) are :




"utf8"=>"✓",
"authenticity_token"=>"1oC/1UdAaTPUepy1zIjO1x6n67Th..",
"metrics_controller"=>
"IsValid"=>"False",
"Comments"=>"1"
,
"commit"=>"Save",
"id"=>"1"



So the key isValid is under the key metrics_controller.
Then, with this kind of coming data, in your controller, you should call



params
.require(:metrics_controller)
.permit(:IsValid, :Comments, :id)


You should take care of the naming convention (snake_case instead of CamelCase), but the most important thing is that the form that is responsible of this request should name inputs accordingly to what's your controller expect.



Then, you should name form elements with something like (according to your screenshot)



<select name="metric[is_valid]">
<option value="1">Yes</option>
<option value="0">No</option>
</select>


With that kind of naming, data will be scoped in key metric instead of metric_controller, and it'll go through strong params.






share|improve this answer
































    1














    By convention in ruby, and rails, you should almost always use snake_case for methods and variables; not CamelCase.



    You haven't quite provided enough information for me to say this with 100% certainty (in particular, what is the database schema for the metrics table?), but that is almost certainly the cause of the problem here.



    Your Metric class likely has attributes such as value, score, is_valid, etc. But you are trying to update attributes named Comments and IsValid. These attributes do not exist, so nothing gets updated.




    Change your view to use snake_case, and permit variables in snake_case; then it should work. It would be possible to make it work using CamelCase like you've done here, but that's against conventions - so would require more effort.






    share|improve this answer























    • I agree that the first step is to get the naming conventions fixed in this code. Hopefully whatever is calling this update method is not passing the params as CamelCase. If so that should be fixed as well. This is the second question I've seen this week where not following Rails' naming convention has caused an app to not work.

      – Dan
      Nov 14 '18 at 15:46






    • 1





      @Dan "Hopefully whatever is calling this update method is not passing the params as CamelCase" -- It looks like it is, though! From the OP's console log: "metrics_controller"=>"IsValid"=>"False", "Comments"=>"1".

      – Tom Lord
      Nov 14 '18 at 16:02











    • yikes, I see that now. It would be nice to see the schema to see how far reaching this unconventional naming is. It's possible the DB fields are camel case. Ultimately, the OP just needs to be consistent across all parts of his app. It's possible he is and case isn't the issue...

      – Dan
      Nov 14 '18 at 16:44


















    0














    As @Tom Lord mentioned, the case of your parameters looks suspicious and might be causing your problem. If you could provide your schema for the metrics table that will help us help you.



    Rails will always work at its best when you follow the naming conventions. This most importantly includes using the correct case and singular/plural names.



    This is how I'd expect your code to look if it were written the Rails way:



    def update
    @metric = Metric.find(params[:id])
    if @metric.update(post_params)
    redirect_to metrics_path
    else
    render 'edit'
    end
    end

    private

    def post_params
    params.permit(:metric, :wi, :value, :ut, :score, :is_valid, :user_name, :comments)
    end





    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301133%2funable-to-save-update-the-record-into-db-in-rails%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      The params that are coming from the request (from the logs) are :




      "utf8"=>"✓",
      "authenticity_token"=>"1oC/1UdAaTPUepy1zIjO1x6n67Th..",
      "metrics_controller"=>
      "IsValid"=>"False",
      "Comments"=>"1"
      ,
      "commit"=>"Save",
      "id"=>"1"



      So the key isValid is under the key metrics_controller.
      Then, with this kind of coming data, in your controller, you should call



      params
      .require(:metrics_controller)
      .permit(:IsValid, :Comments, :id)


      You should take care of the naming convention (snake_case instead of CamelCase), but the most important thing is that the form that is responsible of this request should name inputs accordingly to what's your controller expect.



      Then, you should name form elements with something like (according to your screenshot)



      <select name="metric[is_valid]">
      <option value="1">Yes</option>
      <option value="0">No</option>
      </select>


      With that kind of naming, data will be scoped in key metric instead of metric_controller, and it'll go through strong params.






      share|improve this answer





























        1














        The params that are coming from the request (from the logs) are :




        "utf8"=>"✓",
        "authenticity_token"=>"1oC/1UdAaTPUepy1zIjO1x6n67Th..",
        "metrics_controller"=>
        "IsValid"=>"False",
        "Comments"=>"1"
        ,
        "commit"=>"Save",
        "id"=>"1"



        So the key isValid is under the key metrics_controller.
        Then, with this kind of coming data, in your controller, you should call



        params
        .require(:metrics_controller)
        .permit(:IsValid, :Comments, :id)


        You should take care of the naming convention (snake_case instead of CamelCase), but the most important thing is that the form that is responsible of this request should name inputs accordingly to what's your controller expect.



        Then, you should name form elements with something like (according to your screenshot)



        <select name="metric[is_valid]">
        <option value="1">Yes</option>
        <option value="0">No</option>
        </select>


        With that kind of naming, data will be scoped in key metric instead of metric_controller, and it'll go through strong params.






        share|improve this answer



























          1












          1








          1







          The params that are coming from the request (from the logs) are :




          "utf8"=>"✓",
          "authenticity_token"=>"1oC/1UdAaTPUepy1zIjO1x6n67Th..",
          "metrics_controller"=>
          "IsValid"=>"False",
          "Comments"=>"1"
          ,
          "commit"=>"Save",
          "id"=>"1"



          So the key isValid is under the key metrics_controller.
          Then, with this kind of coming data, in your controller, you should call



          params
          .require(:metrics_controller)
          .permit(:IsValid, :Comments, :id)


          You should take care of the naming convention (snake_case instead of CamelCase), but the most important thing is that the form that is responsible of this request should name inputs accordingly to what's your controller expect.



          Then, you should name form elements with something like (according to your screenshot)



          <select name="metric[is_valid]">
          <option value="1">Yes</option>
          <option value="0">No</option>
          </select>


          With that kind of naming, data will be scoped in key metric instead of metric_controller, and it'll go through strong params.






          share|improve this answer















          The params that are coming from the request (from the logs) are :




          "utf8"=>"✓",
          "authenticity_token"=>"1oC/1UdAaTPUepy1zIjO1x6n67Th..",
          "metrics_controller"=>
          "IsValid"=>"False",
          "Comments"=>"1"
          ,
          "commit"=>"Save",
          "id"=>"1"



          So the key isValid is under the key metrics_controller.
          Then, with this kind of coming data, in your controller, you should call



          params
          .require(:metrics_controller)
          .permit(:IsValid, :Comments, :id)


          You should take care of the naming convention (snake_case instead of CamelCase), but the most important thing is that the form that is responsible of this request should name inputs accordingly to what's your controller expect.



          Then, you should name form elements with something like (according to your screenshot)



          <select name="metric[is_valid]">
          <option value="1">Yes</option>
          <option value="0">No</option>
          </select>


          With that kind of naming, data will be scoped in key metric instead of metric_controller, and it'll go through strong params.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 15:24

























          answered Nov 14 '18 at 17:18









          kevchakevcha

          549513




          549513























              1














              By convention in ruby, and rails, you should almost always use snake_case for methods and variables; not CamelCase.



              You haven't quite provided enough information for me to say this with 100% certainty (in particular, what is the database schema for the metrics table?), but that is almost certainly the cause of the problem here.



              Your Metric class likely has attributes such as value, score, is_valid, etc. But you are trying to update attributes named Comments and IsValid. These attributes do not exist, so nothing gets updated.




              Change your view to use snake_case, and permit variables in snake_case; then it should work. It would be possible to make it work using CamelCase like you've done here, but that's against conventions - so would require more effort.






              share|improve this answer























              • I agree that the first step is to get the naming conventions fixed in this code. Hopefully whatever is calling this update method is not passing the params as CamelCase. If so that should be fixed as well. This is the second question I've seen this week where not following Rails' naming convention has caused an app to not work.

                – Dan
                Nov 14 '18 at 15:46






              • 1





                @Dan "Hopefully whatever is calling this update method is not passing the params as CamelCase" -- It looks like it is, though! From the OP's console log: "metrics_controller"=>"IsValid"=>"False", "Comments"=>"1".

                – Tom Lord
                Nov 14 '18 at 16:02











              • yikes, I see that now. It would be nice to see the schema to see how far reaching this unconventional naming is. It's possible the DB fields are camel case. Ultimately, the OP just needs to be consistent across all parts of his app. It's possible he is and case isn't the issue...

                – Dan
                Nov 14 '18 at 16:44















              1














              By convention in ruby, and rails, you should almost always use snake_case for methods and variables; not CamelCase.



              You haven't quite provided enough information for me to say this with 100% certainty (in particular, what is the database schema for the metrics table?), but that is almost certainly the cause of the problem here.



              Your Metric class likely has attributes such as value, score, is_valid, etc. But you are trying to update attributes named Comments and IsValid. These attributes do not exist, so nothing gets updated.




              Change your view to use snake_case, and permit variables in snake_case; then it should work. It would be possible to make it work using CamelCase like you've done here, but that's against conventions - so would require more effort.






              share|improve this answer























              • I agree that the first step is to get the naming conventions fixed in this code. Hopefully whatever is calling this update method is not passing the params as CamelCase. If so that should be fixed as well. This is the second question I've seen this week where not following Rails' naming convention has caused an app to not work.

                – Dan
                Nov 14 '18 at 15:46






              • 1





                @Dan "Hopefully whatever is calling this update method is not passing the params as CamelCase" -- It looks like it is, though! From the OP's console log: "metrics_controller"=>"IsValid"=>"False", "Comments"=>"1".

                – Tom Lord
                Nov 14 '18 at 16:02











              • yikes, I see that now. It would be nice to see the schema to see how far reaching this unconventional naming is. It's possible the DB fields are camel case. Ultimately, the OP just needs to be consistent across all parts of his app. It's possible he is and case isn't the issue...

                – Dan
                Nov 14 '18 at 16:44













              1












              1








              1







              By convention in ruby, and rails, you should almost always use snake_case for methods and variables; not CamelCase.



              You haven't quite provided enough information for me to say this with 100% certainty (in particular, what is the database schema for the metrics table?), but that is almost certainly the cause of the problem here.



              Your Metric class likely has attributes such as value, score, is_valid, etc. But you are trying to update attributes named Comments and IsValid. These attributes do not exist, so nothing gets updated.




              Change your view to use snake_case, and permit variables in snake_case; then it should work. It would be possible to make it work using CamelCase like you've done here, but that's against conventions - so would require more effort.






              share|improve this answer













              By convention in ruby, and rails, you should almost always use snake_case for methods and variables; not CamelCase.



              You haven't quite provided enough information for me to say this with 100% certainty (in particular, what is the database schema for the metrics table?), but that is almost certainly the cause of the problem here.



              Your Metric class likely has attributes such as value, score, is_valid, etc. But you are trying to update attributes named Comments and IsValid. These attributes do not exist, so nothing gets updated.




              Change your view to use snake_case, and permit variables in snake_case; then it should work. It would be possible to make it work using CamelCase like you've done here, but that's against conventions - so would require more effort.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 14 '18 at 13:26









              Tom LordTom Lord

              15.3k22951




              15.3k22951












              • I agree that the first step is to get the naming conventions fixed in this code. Hopefully whatever is calling this update method is not passing the params as CamelCase. If so that should be fixed as well. This is the second question I've seen this week where not following Rails' naming convention has caused an app to not work.

                – Dan
                Nov 14 '18 at 15:46






              • 1





                @Dan "Hopefully whatever is calling this update method is not passing the params as CamelCase" -- It looks like it is, though! From the OP's console log: "metrics_controller"=>"IsValid"=>"False", "Comments"=>"1".

                – Tom Lord
                Nov 14 '18 at 16:02











              • yikes, I see that now. It would be nice to see the schema to see how far reaching this unconventional naming is. It's possible the DB fields are camel case. Ultimately, the OP just needs to be consistent across all parts of his app. It's possible he is and case isn't the issue...

                – Dan
                Nov 14 '18 at 16:44

















              • I agree that the first step is to get the naming conventions fixed in this code. Hopefully whatever is calling this update method is not passing the params as CamelCase. If so that should be fixed as well. This is the second question I've seen this week where not following Rails' naming convention has caused an app to not work.

                – Dan
                Nov 14 '18 at 15:46






              • 1





                @Dan "Hopefully whatever is calling this update method is not passing the params as CamelCase" -- It looks like it is, though! From the OP's console log: "metrics_controller"=>"IsValid"=>"False", "Comments"=>"1".

                – Tom Lord
                Nov 14 '18 at 16:02











              • yikes, I see that now. It would be nice to see the schema to see how far reaching this unconventional naming is. It's possible the DB fields are camel case. Ultimately, the OP just needs to be consistent across all parts of his app. It's possible he is and case isn't the issue...

                – Dan
                Nov 14 '18 at 16:44
















              I agree that the first step is to get the naming conventions fixed in this code. Hopefully whatever is calling this update method is not passing the params as CamelCase. If so that should be fixed as well. This is the second question I've seen this week where not following Rails' naming convention has caused an app to not work.

              – Dan
              Nov 14 '18 at 15:46





              I agree that the first step is to get the naming conventions fixed in this code. Hopefully whatever is calling this update method is not passing the params as CamelCase. If so that should be fixed as well. This is the second question I've seen this week where not following Rails' naming convention has caused an app to not work.

              – Dan
              Nov 14 '18 at 15:46




              1




              1





              @Dan "Hopefully whatever is calling this update method is not passing the params as CamelCase" -- It looks like it is, though! From the OP's console log: "metrics_controller"=>"IsValid"=>"False", "Comments"=>"1".

              – Tom Lord
              Nov 14 '18 at 16:02





              @Dan "Hopefully whatever is calling this update method is not passing the params as CamelCase" -- It looks like it is, though! From the OP's console log: "metrics_controller"=>"IsValid"=>"False", "Comments"=>"1".

              – Tom Lord
              Nov 14 '18 at 16:02













              yikes, I see that now. It would be nice to see the schema to see how far reaching this unconventional naming is. It's possible the DB fields are camel case. Ultimately, the OP just needs to be consistent across all parts of his app. It's possible he is and case isn't the issue...

              – Dan
              Nov 14 '18 at 16:44





              yikes, I see that now. It would be nice to see the schema to see how far reaching this unconventional naming is. It's possible the DB fields are camel case. Ultimately, the OP just needs to be consistent across all parts of his app. It's possible he is and case isn't the issue...

              – Dan
              Nov 14 '18 at 16:44











              0














              As @Tom Lord mentioned, the case of your parameters looks suspicious and might be causing your problem. If you could provide your schema for the metrics table that will help us help you.



              Rails will always work at its best when you follow the naming conventions. This most importantly includes using the correct case and singular/plural names.



              This is how I'd expect your code to look if it were written the Rails way:



              def update
              @metric = Metric.find(params[:id])
              if @metric.update(post_params)
              redirect_to metrics_path
              else
              render 'edit'
              end
              end

              private

              def post_params
              params.permit(:metric, :wi, :value, :ut, :score, :is_valid, :user_name, :comments)
              end





              share|improve this answer



























                0














                As @Tom Lord mentioned, the case of your parameters looks suspicious and might be causing your problem. If you could provide your schema for the metrics table that will help us help you.



                Rails will always work at its best when you follow the naming conventions. This most importantly includes using the correct case and singular/plural names.



                This is how I'd expect your code to look if it were written the Rails way:



                def update
                @metric = Metric.find(params[:id])
                if @metric.update(post_params)
                redirect_to metrics_path
                else
                render 'edit'
                end
                end

                private

                def post_params
                params.permit(:metric, :wi, :value, :ut, :score, :is_valid, :user_name, :comments)
                end





                share|improve this answer

























                  0












                  0








                  0







                  As @Tom Lord mentioned, the case of your parameters looks suspicious and might be causing your problem. If you could provide your schema for the metrics table that will help us help you.



                  Rails will always work at its best when you follow the naming conventions. This most importantly includes using the correct case and singular/plural names.



                  This is how I'd expect your code to look if it were written the Rails way:



                  def update
                  @metric = Metric.find(params[:id])
                  if @metric.update(post_params)
                  redirect_to metrics_path
                  else
                  render 'edit'
                  end
                  end

                  private

                  def post_params
                  params.permit(:metric, :wi, :value, :ut, :score, :is_valid, :user_name, :comments)
                  end





                  share|improve this answer













                  As @Tom Lord mentioned, the case of your parameters looks suspicious and might be causing your problem. If you could provide your schema for the metrics table that will help us help you.



                  Rails will always work at its best when you follow the naming conventions. This most importantly includes using the correct case and singular/plural names.



                  This is how I'd expect your code to look if it were written the Rails way:



                  def update
                  @metric = Metric.find(params[:id])
                  if @metric.update(post_params)
                  redirect_to metrics_path
                  else
                  render 'edit'
                  end
                  end

                  private

                  def post_params
                  params.permit(:metric, :wi, :value, :ut, :score, :is_valid, :user_name, :comments)
                  end






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 15:54









                  DanDan

                  606823




                  606823



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301133%2funable-to-save-update-the-record-into-db-in-rails%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Top Tejano songwriter Luis Silva dead of heart attack at 64

                      ReactJS Fetched API data displays live - need Data displayed static

                      政党