Skip to content

Instantly share code, notes, and snippets.

View leadhkr's full-sized avatar

Sagar Patel leadhkr

View GitHub Profile
[:!, :!=, :!~, :<=>, :==, :===, :=~, :__binding__, :__id__, :__send__, :all?, :any?, :attrs, :chunk, :class, :clone, :collect, :collect_concat, :count, :cycle, :dclone, :define_singleton_method, :detect, :display, :drop, :drop_while, :dup, :each, :each_cons, :each_entry, :each_slice, :each_with_index, :each_with_object, :entries, :enum_for, :eql?, :equal?, :extend, :find, :find_all, :find_index, :first, :flat_map, :freeze, :frozen?, :gem, :grep, :group_by, :hash, :include?, :inject, :inspect, :instance_eval, :instance_exec, :instance_of?, :instance_variable_defined?, :instance_variable_get, :instance_variable_set, :instance_variables, :is_a?, :kind_of?, :lazy, :map, :max, :max_by, :member?, :method, :methods, :min, :min_by, :minmax, :minmax_by, :nil?, :none?, :object_id, :one?, :partition, :pretty_inspect, :pretty_print, :pretty_print_cycle, :pretty_print_inspect, :pretty_print_instance_variables, :private_methods, :protected_methods, :pry, :psych_to_yaml, :public_method, :public_methods, :public_send, :reduc
require 'sinatra'
require 'data_mapper'
require 'pry'
if ENV['RACK_ENV'] != 'production'
require 'dotenv'
Dotenv.load('.env')
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite:wall.db')
end
<p>
<b>Title: </b><%= @wall.title %></br>
<b>Description: </b><%= @wall.description %></br>
<b>Created By: </b><%= @wall.created_by %>
<b>Likes: </b><%= @wall.likes %>
</p>
<p>
<form action="/walls/<%= @wall.id %>/like" method="post">
<input type="hidden" name="_method" value="PUT">
require 'sinatra'
require 'data_mapper'
require 'pry'
if ENV['RACK_ENV'] != 'production'
require 'dotenv'
Dotenv.load('.env')
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite:wall.db')
end

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.

<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>
<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>
<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>
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])
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." },