Skip to content

Instantly share code, notes, and snippets.

@bootcoder
Created August 25, 2016 00:53
Show Gist options
  • Save bootcoder/c568f25682da2f244bd55e7797738f33 to your computer and use it in GitHub Desktop.
Save bootcoder/c568f25682da2f244bd55e7797738f33 to your computer and use it in GitHub Desktop.
baseline_RR_pattern
# Cat INDEX
get '/categories' do
@categories = Category.all
erb :'categories/index'
end
# Cat NEW
get '/categories/new' do
@category = Category.new
erb :'categories/new'
end
# Cat CREATE
post '/categories' do
@category = Category.new(params[:category])
if @category.save
redirect '/categories'
else
@errors = @category.errors.full_messages
erb :'categories/new'
end
end
# Cat SHOW
get '/categories/:id' do
@category = Category.find(params[:id])
erb :'categories/show'
end
# Cat EDIT
get '/categories/:id/edit' do
@category = Category.find(params[:id])
erb :'categories/edit'
end
# Cat UPDATE
put '/categories/:id' do
@category = Category.find(params[:id])
@category.update(params[:category])
redirect "/categories/#{@category.id}"
end
# Cat DESTROY
delete '/categories/:id' do
@category = Category.find(params[:id])
@category.destroy
redirect "/categories"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment