Skip to content

Instantly share code, notes, and snippets.

@English3000
Created December 2, 2017 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save English3000/b7f18db07b5d1c82a5e1f6cc8b7e67f6 to your computer and use it in GitHub Desktop.
Save English3000/b7f18db07b5d1c82a5e1f6cc8b7e67f6 to your computer and use it in GitHub Desktop.

Your AJAX request has a payload. The payload includes routing information, as well as instructions to the controller for which action to execute. Whichever action is executed either creates or does something with an existing instance of a model (a row in a table in your database server).

Once what's done has been done as your action is executed, Rails sends the result to a view. A view is either an HTML template or a JSON object (key-value pairs). This template/view takes in the model data. Voila! There's the unique info that's put on your webpage.

So the controller executes an action, then sends the result into the view. That view plus model data is the response that is sent back and which renders on your browser.

To do all that, you need to know HTML, CSS, JavaScript (the jQuery library has a built-in $.ajax() method--see the Examples at the bottom for the syntax of the payload object), Ruby (or another server-side scripting language), and Rails' Active Record or else SQL. And also the Command Line. The Command Line is what allows you to create (generate) a Rails project (file structure/directory).

So, HTML and CSS to control how your webpage looks, JavaScript to determine when and with what it will access your server, Ruby to write your server's logic which will determine how it accesses the database, some more HTML or JSON for your template/view, and...

  • HTML
  • CSS
  • JavaScript
  • Ruby
  • Command Line

...that's all you need if you don't mind a bunch of page refreshes. But contemporary websites are increasingly using React, a JavaScript library, to get around that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment