Skip to content

Instantly share code, notes, and snippets.

@saylerb
Forked from Carmer/Intro_to_sinatra_check.md
Last active May 9, 2016 17:42
Show Gist options
  • Save saylerb/0415c52ff0b6324a969f0382d280ecf2 to your computer and use it in GitHub Desktop.
Save saylerb/0415c52ff0b6324a969f0382d280ecf2 to your computer and use it in GitHub Desktop.

Introduction to Sinatra

1. What is the purpose of the server file (routing)?

  • The server file contains the routes for specific HTTP verbs, and determines what the client gets back with each request

2. How do you pass variables into the views?

  • Two ways
    • Using an instance variable:
    get '/' do
      @ number = 100
      erb :index
    end
    
    • Using local variable:
    get '/' do
      number = 100
      erb (:index, :locals => {:number => number})
    end
    

3. How can we interpolate ruby into a view (html)?

  • use ERB tags. To render use in the view use <%= RUBY_CODE %>
  • To not render in the view, omit the equals sign: <% RUBY_CODE %>

4. In what format does data come in from a view/form? What do we call it

  • data comes in as a hash. The hash is called params

5. What are params?

  • params are key value pairs that contain information coming from the client through forms.
  • They are stored per request, so they can change with each request that is made
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment