Learning Goals
- Learn about how the browser displays elements
- Differentiate between different position properties and when to use them
- How to use google chrome to debug and fix your css weirdness.
- Exercise:
- Place the ball inside the ring with the least movement (absolute positioning)
-
- Stick to a framework to make it easier for you to handle things
- Where to go from here:
Structure
- 10 - Displays
- 10 - Positions
- 10 - Let's play around with both
- 20 - Exercise
A world with no Ajax
- In order for use to change one portion of our page, we have to reload the whole page.
- If there's any area in our page that takes time to load, the user has to wait before the page is rendered.
What's Ajax
- Asynchronous JavaScript and XML
- Most use JSON instead of XML
- It's now one of the most important features in client side development (front end)
When to use Ajax
- Updating an item on the page without reloading the whole page.
- Requesting a new page and showing it without reloading the whole page (essentially all the JS frameworks out there)
- Connecting to any API to either send or get data.
- If you want to be hip and cool and show off your Javascript wizardry.
JQuery and AJAX
- JQuery provides an easy way to make AJAX Calls
- AJAX essentially is a request made to an API and the response doesn't interrupt our page loading.
- A response comes in the form of: JSON, AJAX or even HTML
- We will deal with JSON in this class, XML is similar.
- Once a response comes back, we should handle displaying the data ourselves.
Draw a diagram to show how the Request response cycle worksConnecting Rails
- Let's Generate a Rails app.
- Clone https://github.com/JumpstartLab/blogger_advanced
- Go to See All Articles or /articles route.
- Try to delete an article
- Notice how the page has to be reloaded to display the new results.
- Let's add AJAX functionality here
Steps to adding AJAX to rails
-
you have two main areas you want to deal with:
- Rails controller: make sure you rails controller returns back JSON result to be displayed. (respond with)
- Javascript Side: call your controller route and display the result in the callback
-
Rails Side, in our controller, we would do:
Exercise
Create a 5 second fake delay on the update action in the ArticlesController.
Verify that the articles take longer to update.
Create an UpdateJob that handles that delay.
Enqueue the fake delay in your update action.
Make sure that the delay is no longer there.
Recap
Background Jobs
What is Redis
How to install Resque
How to enqueue a job
How to start a worker
How to format the output of Resque
How to install Foreman