Skip to content

Instantly share code, notes, and snippets.

@s-espinosa
Forked from Carmer/Intro_to_sinatra_check.md
Last active March 22, 2016 04:50
Show Gist options
  • Save s-espinosa/749df58d13809b5f6a01 to your computer and use it in GitHub Desktop.
Save s-espinosa/749df58d13809b5f6a01 to your computer and use it in GitHub Desktop.

Introduction to Sinatra

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

Take input from a client and figure out what to do with it (e.g. what to return, what to change on a server, what to delete, etc.)

2. How do you pass variables into the views?

ERB can reference an instance variable from the server file. Can also send variables as locals. In the code below the :number symbol in the :locals hash is what will be used in the erb template to reference the variable, number (not a symbol) references the number variable in the server file.

get '/' do
  number = 8
  erb(:index, :locals => {:number => number })
end

3. How can we interpolate ruby into a view (html)? Use use an erb template and send a message from within the server file using the erb function.

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?

Parameters that can be accessed by the server file as a hash (e.g. params[:name])

@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