title: rails update checkbox value with ajax
body: <p>Hi I'm trying to update a rails form with ajax but I don't know how.</p>
  
  <p>What i know about ajax in rails is: that i need to set up remote:true in the form and then i have to create a file called the same but instead of *.html.erb i do *.js.erb.</p>
  
  <p>Now I'm using a form in the show.html.erb which calls the method edit.html.erb ... Do i have to write the js code into edit.js.erb or show.js.erb?</p>
  
  <p>I got checkboxes and they should be updated everytime i click on them. </p>
  
  <p>Can someone point me in the right direction and provide some jquery code? I have to no idea how to solve that problem.</p>
  
  <p>Thanks in advance</p>
  
  <p>show.html.erb</p>
  
  <pre><code>&lt;%= form_for @order, remote:true do |g| %&gt;
  &lt;%= g.label "recieve sms?" %&gt;
  &lt;%= g.check_box :send_sms %&gt;
  &lt;%= g.label "recieve email?" %&gt;
  &lt;%= g.check_box :send_email %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>def update
      @order = Order.find(params[:id])
      respond_to do |format|
      if @order.update_attributes(params[:order])
          format.js { render json: @order, status: "200" }
      else
          format.js { render json: @order, status: "400" }
      end
  end
  end
  </code></pre>
  
  <p>somekind of of try:</p>
  
  <pre><code>$.ajax('/orders/613', {
      type: 'PUT',
      success: function(data) {
          alert('works !');
      }
  });
  </code></pre>