GithubHelp home page GithubHelp logo

daretodiscover's Introduction

Dare To Discover... wine?

In this lab we will use AJAX to request data from an API about wine. We will use jQuery make an AJAX request to http://daretodiscover.net/wine and display the resulting list of wines. This should all be done in the context of a Ruby on Rails app.

Steps

  1. Create a Ruby on Rails app.
  2. Make a controller and route that renders a home page.
  3. On the home page, include JavaScript that calls http://daretodiscover.net/wine.
    • Hint: by default Rails gives us a .coffee file. Replace it with a .js file and remove the coffeescript-style comments.
    • Hint: use one of jQuery's $.ajax or $.getJSON() methods.
  4. When the results are returned, make sure you can log them to the console.
    • Ponder: what datatype is the result?
    • Ponder: how will you be able to turn the returned data into an HTML list?
  5. Start to render the list of wines onto the page via JavaScript and realize there must be a better way.
    • Hint: would you use document.createElement("ul")?
    • Hint: could you use $("<ul>")?
  6. Decide to integrate Handlebars templates instead of using either of those options.

Handlebars Steps

  1. Include the handlebars_assets gem in your Gemfile.

     # Gemfile
     gem 'handlebars_assets'
    
  2. Don't forget to run bundle install and then restart your Rails server.

    bundle install
    rails server
    
  3. Create a folder called templates in your app/assets/javascripts folder.

    # inside of app/assets/javascripts directory
    mkdir templates
    
  4. Add a .hbs template in your newly created templates directory.

    # inside of templates directory
    touch wine.hbs
    
  5. Add the following lines to application.js so it includes the Handlebars template you've created.

    //= require handlebars.runtime
    //= require_tree ./templates
    

    Careful: Does the handlebars_assets documentation say anything specific about where require_tree ./templates needs to be included relative to require_tree .?

  6. Add some Handlebars syntax to your .hbs file. You may want to check out {{#each}}.

  7. In your original JavaScript file, access your new template though

    var template = HandlebarsTemplates["wine"];
    var html = template(wineResultsJSON);
    // render that html to the page (w/ jQuery?)
    
  8. Fix bugs (and read docs) until it works.

daretodiscover's People

Contributors

tlicata avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.