Skip to content

Instantly share code, notes, and snippets.

@theonlyrao
Forked from Carmer/Intro_to_sinatra_check.md
Last active March 22, 2016 04:36
Show Gist options
  • Save theonlyrao/1c7c8b62a4a1f9c1af71 to your computer and use it in GitHub Desktop.
Save theonlyrao/1c7c8b62a4a1f9c1af71 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 accepts, parses, and controls the sending of the response. It will contain get or post etc. verb blocks based on the client's chosen path and then contain instructions for the rest of the web application to follow in collecting information from a database and then rendering that information in the context of the user's request.

2. How do you pass variables into the views?

  • Make the variable a local variable, var. Then pass the variable as an argument into the view as a hash.
  • Make the variable an instance variable that is then available within the view - because of scope? or because of tricky self things?
  • Make the variable a class variable so it is avaialble globally but actually don't do this.

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

The view has access to any variables that are in the scope of the method from the server. Ruby is available in the view by either <% #ruby_code %> to keep the ruby in the background or <%= ruby_variable %> to have the ruby be visible.

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

Data comes in from the view as html. Data comes in from the form as a hash stored in params. The values entered in the form are available by calling params[:form_field_name].

5. What are params?

Params is a hash of values that is availble in any server block which responsds to a request by the client in which the client enters data.

@Carmer
Copy link

Carmer commented Mar 22, 2016

"Make the variable a class variable so it is avaialble globally but actually don't do this." haha yes. Looks good. it's important to note that the params hash may container data not from the form, but yes all data from the form will come through in the params hash

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