"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
Â
Dash of ajax
1. Add a Dash of Ajax Jason Noble http://jasonnoble.org
2. Partial Templates Methods for views Move a portion of your view to a separate file Invoke a given partial from multiple locations Another view Controller
4. Rails render method takes a collection as an argument renders a partial view for each item Partials filenames start with with _ _line_item.html.erb Inside the partial we will have a variable available the same name as the partial _line_item partial has variable line_item
13. app/views/line_items/create.js.rjs Render JavaScript page is a JavaScript generator Replaces HTML content of the id cart with the rendered HTML Now clicking Add to Cart doesnât refresh the page, just the cart div
14. Highlight Changes Product owner wants a visual cue that the cart has been updated Weâll use the script.aculo.usâ provided yellow fade technique See other effects at http://madrobby.github.com/scriptaculous/demos/
18. Hide Empty Carts Customer would like to hide the cart if it is empty Weâll do this first via not rendering the HTML if the cart is empty Then weâll make it smoother by adding another JavaScript effect
25. Run tests rake test 1 failure, 9 errors You can see errors as well http://localhost:3000/products @cart is not being set in the products controller Letâs make it optional
30. What we did Moved shopping cart into sidebar Used :remote => true to Ajaxify our buttons Used RJS template to update page Added highlight effect to show changes Wrote helper to hide cart when itâs empty Wrote tests to verify Ajax actions
31. Homework Make clicking the image of the book add the item to the cart via Ajax Change Empty Cart action to use Ajax and blind_up effect Experiment with other visual effects available Add a link in the cart next to each item. Clicking the item should decrement the quantity of that item. Write a view test to verify the empty cart is not viewable