Skip to content

Instantly share code, notes, and snippets.

View ericbooker12's full-sized avatar

Eric Booker ericbooker12

  • San Francisco Bay Area
View GitHub Profile
@ericbooker12
ericbooker12 / gist:4cced394f2e165b86ca09f433d3437ac
Created August 18, 2016 01:07 — forked from victorwhy/gist:45bb5637cd3e7e879ace
How Sinatra routes PUT/PATCH and DELETE

HTML and Sinatra really only support the GET and the POST methods. In order to be able to use the PUT and DELETE methods in Sinatra, you kind of have to "trick" the form to go to the right place. Then you can name the routes the proper way - otherwise you can only really work with GET and POST.

I used the Craiglist Jr challenge for some examples. Let's look at a quick example of a POST form/method/route- in this case, we're creating a new Craigslist article:

POST form and corresponding route:

<form action="/article/new" method="post">
  --------------------------------
  YOUR FORM FIELDS HERE
@ericbooker12
ericbooker12 / README
Created July 19, 2016 02:07 — forked from jkarnowski/README
Sessions-Users-Example-CRUD
Add helpers here as *.rb files, e.g.,
app/helpers/formatting.rb
helpers do
def em(text)
"<em>#{text}</em>"
end
end
@ericbooker12
ericbooker12 / hospital.rb
Created June 24, 2016 20:28 — forked from kenrett/hospital.rb
Hospital MVC Example
class Hospital
attr_reader :patients, :name
def initialize(name, patients = [])
@name = name
@patients = patients
end
def find_patient_by_name(name)
patients.find { |patient| patient.name == name }