title: Rails only pass params that have changed on edit submit
body: <p>I have a edit form that prepopulates with the current values. Its a custom edit screen (not the default one that rails uses) and what Im using it for is for users to submit changes that will get voted on and might eventually get applied to the record. However, in the time it takes to be voted on something else might have changed and I dont want to overwrite the changes if they didnt submit a change. </p>
  
  <p>EDIT: Changing to my more specific case so hopefully answers will work for it...</p>
  
  <p>I have the following tables: Recipes, RecipeIngredients, RecipeSteps, RecipeChanges.  On the show view of my recipes it displays all the ingredients/steps and there is a tab that then changes just the ingredients/steps to forms as to allow the user to submit changes.  I dont want these changes applied though.  Instead Im trying to create a voting system where people can vote on them.  So what I have decided on is to convert the parameters from the form into a json string and save it in the RecipeChanges table under a single column (instead of using two table for ingredient changes and step changes).  Heres the code for the form (html removed to make it easier to see the rails stuff):</p>
  
  <pre><code>&lt;%= form_for @recipe, url: recipe_recipe_changes_path(@recipe), html: {method: "post"}, remote: true do |f| %&gt;
      &lt;%= f.fields_for :recipe_ingredients, f.object.recipe_ingredients.order(:order) do |ff| %&gt;
          &lt;%= ff.hidden_field :order, class: "position" %&gt;
          &lt;%= ff.text_field :ingredient, placeholder: "Add Ingredient (e.g. 3 cups cooked rice)" %&gt;
          &lt;label&gt;&lt;%= ff.check_box :_destroy %&gt;Remove&lt;/label&gt; 
      &lt;% end %&gt;
      &lt;%= f.fields_for :recipe_steps do |ff| %&gt;
          &lt;%= ff.hidden_field :order, class: "position"%&gt;
          &lt;%= ff.text_area :step %&gt;
          &lt;label&gt;&lt;%= ff.check_box :_destroy %&gt;Remove&lt;/label&gt; 
      &lt;% end %&gt;
      &lt;%= submit_tag "Submit", class: "button" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>So this sends a recipe object to my RecipeChange controller and there I handle the params to save them as the json string like so:</p>
  
  <pre><code>def create
      @change = RecipeChange.new
      @change.recipe_id = params[:recipe_id]
      @change.new_recipe = recipe_change_params.to_json
      #if @change.save
        #add alert for successfully adding
      #else
        # add code for error handling
      #end
    end
  </code></pre>
  
  <p>This works like I want except for it saves all the ingredients/steps and I would like to only save what they have changed.  I had two thoughts on how to do this but not sure how to accomplish it.</p>
  
  <ol>
  <li><p>Check if the fields have changed when they click the submit button and only send the ones that have been edited (not sure if possible)</p></li>
  <li><p>In the controller grab the original recipe (I have the id so that would be easy) and loop through the ingredients/steps and compare them and remove any that are identical....this is the method I think would be better but not sure how to loop through the hashes to accomplish this</p></li>
  </ol>