Skip to content

Instantly share code, notes, and snippets.

@pindell-matt
Forked from Carmer/Intro_to_sinatra_check.md
Last active March 22, 2016 04:47
Show Gist options
  • Save pindell-matt/709896e3d9cbdbeda3ce to your computer and use it in GitHub Desktop.
Save pindell-matt/709896e3d9cbdbeda3ce to your computer and use it in GitHub Desktop.

Introduction to Sinatra

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

To provide different responses to different requests - taking the user to different pages / down different paths, to update or access different information, depending on the different requests (GET, POST, DELETE, etc.)

2. How do you pass variables into the views?

You can pass in instance variables (without explicitly passing them through the :locals hash) or local variables (in which case you must explicitly use the :locals hash ex: erb(:index, :locals => {:example => example})

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

By using embedded ruby files (.erb) and placing all code you want to display within: <%= code_to_display %> and content you want to simply run within: <% code_to_run %>

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

Any and all data submitted by users comes in as a hash called "params"

5. What are params?

Params is a hash containing all information submitted by the client, via forms. They are available to be used in .erb files, as variables, ex: params[:example_param]

@Carmer
Copy link

Carmer commented Mar 22, 2016

It's important to note that not all data in the params hash has to come from the user, but yes, data from the user comes through in the params.

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