Skip to content

Instantly share code, notes, and snippets.

View jwashke's full-sized avatar

Josh Washke jwashke

View GitHub Profile

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.

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

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
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
@jwashke
jwashke / cfu_crud_in_sinatra.markdown
Last active March 23, 2016 04:23 — forked from rwarbelow/cfu_crud_in_sinatra.markdown
CRUD in Sinatra -- Check for Understanding
1. Define CRUD.

Create Read Update Delete

2. There are seven verb + path combinations that are necessary in a basic Sinatra app in order to provide full CRUD functionality. List each of the seven combinations, and explain what each is for.
  • GET 'somethings'
    • See a list of all things
  • GET 'somethings/thingid'
    • See a specific thing
  • GET 'somethings/new'
    • See form to create new thing
  • POST 'somethings'

Sequel

SQL: Declarative RUBY: Object oriented

Object Relational Mappers

Written in an object oriented language and wrapped around a relational database The object classes are mapped to the data tables in the database and the object instances are mapped to individual rows in that database

Ruby ORMs

  • Active Record (used a lot)
  • DataMapper (used a bit)

Models, Databases, Relationships in Rails

What is the difference between a primary key and a foreign key? Where would we find a primary key? What would it be called by default? Where would we find a foreign key? What is the naming convention for a foreign key?

A primary key is the primary unique identifier of a table, a foreign key is the primary key of another table that serves as as the relationship between the two tables. A primary key is generally named id, a foreign key is named othertable_id whith the name of the table the foriegn key links to followed by id.

Write down one example of:

  • a one-to-one relationship.
    • Each car has one license plate and each license plate belongs to one car
  • a one-to-many relationship.
    • A School has many students but each student has only one school
  • a many-to-many relationship.

Sass

Whats wrong with CSS?

  1. Its very repetitive
  2. its organization is a mess
  3. changing one thing like the color or font can be a nightmare

How you can dry up your code with just a little bit of Sass

Variables

Proper commit messages

Seven rules for commit messages

  • Separate subject from body with a blank line
  • Limit the subject line to 50 characters
  • Capitalize the subject line
  • Do not end the subject line with a period
  • Use the imperative mood in the subject line
  • Wrap the body at 72 characters
  • Use the body to explain what and why vs. how Explanation for these rules can be found here

Setting Group Expectations

Group Member Names: Jared, Josh, Sunny

  1. When are group members available to work together? What hours can each group member work individually? Are there any personal time commitments that need to be discussed? Anytime. Josh needs to catch the last train but thats pretty late.

  2. How will group members communicate? How often will communication happen, and how will open lines of communication be maintained? Private slack channel