Skip to content

Instantly share code, notes, and snippets.

View jwashke's full-sized avatar

Josh Washke jwashke

View GitHub Profile
What users want CRUD Action(URL) Method/Verb Data prep/manipulation Redirect/Render View
See all tasks read '/tasks' GET @tasks = task_manager.all render :index
See one task read '/tasks/:id' GET @task = task_manager.find(id) render :show
See form to put new task into create '/tasks/new' GET none render :new
Submit form to create new task create '/tasks' POST task_manager.create(params[:task]) redirect to '/tasks'
See a form to edit task info upda

How the Web Works

What happens when you enter a url into the address bar of a web browser and hit enter

  • This is a common interview question

Hypertext Transfer Protocol (HTTP)

Stores no state, simple text documents transferred back and forth.

HTTP Verbs
  • GET - Retrieve information identified by the Request-URI
    • GET /users => All users
  • POST - Create a new resource identified by the Request-URI

Sinatra

  • Ruby gem
  • Domain-specific language (DSL)
  • minimal effort Ruby library that makes HTTP access and simple web apps easy
  • Much more light weight than rails so more suitable for smaller simpler applications.

Things about Sinatra

  • modular vs classic style
  • Rack-compatible

Introduction to Sinatra

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

The server file serves as the main point of contact between the client and the server. The server file takes in the http request from the client and routes the client to the proper page base on the verb and the path of the http request.

2. How do you pass variables into the views?

Instance variables are useable in the view when it is rendered. local variables you pass in using a key value hash erb(:index, locals => { :name_in_view => name_in_server }

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

Using ERB (Embedded RuBy) in the server call the erb method and tell it the view you want it to render.