Skip to content

Instantly share code, notes, and snippets.

View leadhkr's full-sized avatar

Sagar Patel leadhkr

View GitHub Profile
# Method name: item_counts
# Input: An arbitrary array
#
# Returns: A hash where every item is a key whose value is the number of times
# that item appears in the array
#
# Prints: Nothing
# Version 0.1
# ====================================================
require "fileutils"
# CREATE DIRECTORY
def directory
unless Dir.exist?("public")
Dir.mkdir("public")
Dir.mkdir("public/img")
end
end
require "fileutils"
# CREATE DIRECTORY
def directory
unless Dir.exist?("public")
Dir.mkdir("public")
Dir.mkdir("public/img")
end
end
def run_app(command, arguments)
if command == "timeline"
user_timeline(arguments[0])
elsif command == "info"
user_info(arguments[0])
elsif command == "followers"
user_followers(arguments[0])
end
end
require 'sinatra'
require 'uri'
QUOTES=[{ :author => "E. W. Dijkstra", :quote => "The computing scientist’s
main challenge is not to get confused by the complexities of his own
making." },
{ :author => "Ken Thompson", :quote => "One of my most productive days
was throwing away 1000 lines of code." },
require 'sinatra'
require_relative 'db'
get '/' do
@recipes = Recipe.all
erb :recipes
end
get '/recipes/:recipe_id' do
if @recipe = Recipe.get(params[:recipe_id])
<h1>Granny Goodnesses Greatest Recipes</h1>
<% @recipes.each do |recipe| %>
<article>
<h3><a href="/recipes/<%=recipe.id%>"><%= recipe.title %></a></h3>
<p class="description"><%= recipe.description %></p>
</article>
<% end %>
<h2>Add Your Own!</h2>
<p>
<p>Enter Author name to Edit Wall:</p>
<form action="/walls/<%= @wall.id %>" method="PUT">
<p>
<input type ="text" name="title" value="<%= @wall.title %>"><br/>
<input type ="text" name="description" value="<%= @wall.description %>"><br/>
</p>
<p>
<p>Enter Author name to Edit Wall:</p>
<form action="/walls/<%= @wall.id %>/edit" method="PUT">
<p>
<input type ="text" name="title" value="<%= @wall.title %>"><br/>
<input type ="text" name="description" value="<%= @wall.description %>"><br/>
</p>
<p>

RESTful Services You've heard of the two terms GET and POST.

But GET and POST aren't the only "HTTP verbs" - there's two more you should know about: PUT and DELETE.

Technically, POST should only be used for creating something - like creating a new Note in your awesome new web app, for example.

PUT is the verb for modifying something. And DELETE, you guessed it, is for deleting something.

Having these four verbs is a great way to separate an app up. It's logical. Unfortunately, web browsers don't actually support PUT or DELETE requests, which is why you've likely never heard of them before.