title: making rails respond_to format js for an Ajax request
body: <p>I'm trying to make an Ajax request that makes an update upon a radio button click without reloading an entire page. </p>
  
  <p>Update action definition in my controller. There really not that much info on this part in the Rails docs. </p>
  
  <pre><code> def update
      if @rsvp.update(rsvp_params)
        respond_to do |format|
          format.js
        end
      end
    end
  </code></pre>
  
  <p>update.js.erb, not sure if this code even works, but I can't test it since Rails is not even finding it: </p>
  
  <pre><code>$(document).on('ready', function() {
      $('.rsvp').on('click', function(e) {
          e.preventDefault()
  
          var user_id = $(.rsvp).data('user-id')
          var rsvp_id = $(.rsvp_id).data('rsvp-id')
  
          $.ajax({
              type: 'POST',
              url: "users/" + user_id + "/rsvps/" + rsvp_id
          }).done(function(response){ console.log('hello?', response)
          })
      })
  })
  </code></pre>
  
  <p>App currently breaks down with <code>ActionController::UnknownFormat in RsvpsController#update</code> at the <code>respond_to</code> line. This posting is an extension of <a href="https://stackoverflow.com/questions/40183987/using-ajax-jquery-for-update-action-without-page-reload">this one, which is trying to solve too many problems at once</a>. </p>
  
  <p>log</p>
  
  <pre><code>Processing by RsvpsController#update as HTML
    Parameters: {"utf8"=&gt;"✓", "rsvp"=&gt;{"event_id"=&gt;"16", "status"=&gt;"attending"}, "user_id"=&gt;"1", "id"=&gt;"11"}
    Rsvp Load (3.3ms)  SELECT  "rsvps".* FROM "rsvps" WHERE "rsvps"."id" = $1 LIMIT $2  [["id", 11], ["LIMIT", 1]]
     (0.2ms)  BEGIN
    Event Load (2.5ms)  SELECT  "events".* FROM "events" WHERE "events"."id" = $1 LIMIT $2  [["id", 16], ["LIMIT", 1]]
    User Load (1.4ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
    SQL (0.7ms)  UPDATE "rsvps" SET "status" = $1 WHERE "rsvps"."id" = $2  [["status", 2], ["id", 11]]
     (2.4ms)  COMMIT
  Completed 406 Not Acceptable in 82ms (ActiveRecord: 20.6ms)
  
  
  
  ActionController::UnknownFormat (ActionController::UnknownFormat):
  
  app/controllers/rsvps_controller.rb:19:in `update'
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>in my routes file, I did <code>resources :rsvps, defaults: { format: 'js' }</code>. This got the app to process the request as JS, instead of HTML, but now it renders the update.js.erb file. DB gets updated, but no partial reload happens as desired. </p>