Giter VIP home page Giter VIP logo

reddit-reader's Introduction

Sinatra Practice

Description

Note: The following instructions assume using a Mac.

You'll need Ruby and a few Ruby libraries, referred to as 'gems'.

Taken from the Ruby Wiki:

"Mac's with version 10.5 Leopard or higher already have Ruby and RubyGems installed, Ruby and RubyGems update instructions are found here at the Homebrew for OS X page, as well as instructions for adding Homebrew to your OS X machine if you do not already have it installed."

To get your server started, simply run the following:

# install the bundler library/commands
$ gem install bundler

# download this project's dependencies
$ bundle install

# start the server
$ ruby app.rb

Finally, visit http://localhost:4567/, and you'll have a local server! You should see a blank page.

Some info about the files and folders

  • views/ - HTML and embedded Ruby logic
  • app.rb - configuration, endpoints, Ruby logic to make it work

Requirements of this exercise

There is commented code in each of the files referenced below. Do not change the source code but use the following directions to add to it.

  1. In views/index.html, create:

    • a form with a POST method and an action of /results
    • an input element in the form with an id and name of subreddit
  2. In app.rb have the / endpoint load the index.html file

  3. Also in the app.rb file, in the the /results endpoint:

     - using the params hash, store the subreddit key value in a variable called "subreddit"
     - send a get request to "http://reddit.com/r/#{subreddit}.json" using the ruby gem [HTTParty](https://github.com/jnunemaker/httparty) and store the results of the request in a variable called `returned_results`
     - load the `results.erb` 
    
  4. Use an img tag to make it so the URL in the results.erb is shown as a picture in the HTML

Deliverable

The form should look like this:

...and on submit:

Resources

reddit-reader's People

Contributors

jnappy avatar

Watchers

 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.