Ajax and Rails

This is just a short post to save a few links and document that "Server Javascript Responses" in Rails are still useful in 2018/19.

Lifecycle of SJR

The basic idea behind Server Javascript Responses (SJR) is diagrammed below:


SJR works like this:

  1. A User submits a form that has the Rails attribute remote=true on the form tag which makes the form submission happen via AJAX. See the Rails guide for more information.

  2. The server receives the data payload and processes a response.

  3. The Response from the server is a blob of JS not JSON that usually comes from a matching name.js.erb template.

  4. The User's browser receives the JS blog and evals the JS to update the page.


  1. DHH's original post
  2. Medium post about eschewing fancy front-end frameworks for SJR
  3. Ajax calls the Rails way
Have a comment? Send an email to my public inbox. Please follow proper mail etiquette.