Skip to content

Instantly share code, notes, and snippets.

@lingtran
Forked from Carmer/Intro_to_sinatra_check.md
Last active March 22, 2016 04:02
Show Gist options
  • Save lingtran/5ac0d06c3138d50fa451 to your computer and use it in GitHub Desktop.
Save lingtran/5ac0d06c3138d50fa451 to your computer and use it in GitHub Desktop.

Introduction to Sinatra

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

It is the gatekeeper of the application. It's the first response in the request/response chain. It takes information from a request, parses it and then executes to plan depending on the HTTP verb, which determines what the client gets back.

2. How do you pass variables into the views?

Either as instance variable or local variables within the verb block. If local variable, utilize :locals, paired with view erb file/variable.

Ex: Instance Variable

get '/' do @number = 8 erb :index end

Ex: Local variable get '/' do number = 8 erb(:index, :local => { :number => number, :count => 12 } ) end

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

<%= ruby_code%> in ERB file.

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

a hash called params

5. What are params?

values assigned to the 'names' in the form/input tag are the keys to the params.

@Carmer
Copy link

Carmer commented Mar 22, 2016

Looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment