daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Jun 5th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ENV['RACK_ENV'] ||= 'development'
  2.  
  3. require 'sinatra/base'
  4. require_relative 'data_mapper_setup'
  5.  
  6. class Chitter < Sinatra::Base
  7.  
  8.   enable :sessions
  9.  
  10.   helpers do
  11.     def current_user
  12.       @user ||= User.get(session[:user_id])
  13.     end
  14.   end
  15.  
  16.   get '/peeps' do
  17.     @peeps = Peep.all
  18.     erb :'peeps/index'
  19.   end
  20.  
  21.   get '/peeps/new' do
  22.     erb :'peeps/new'
  23.   end
  24.  
  25.   post '/peeps' do
  26.     Peep.create(message: params[:message], user_id: current_user.id)
  27.     redirect '/peeps'
  28.   end
  29.  
  30.   get '/users/new' do
  31.     erb :'users/new'
  32.   end
  33.  
  34.   post '/users' do
  35.     user = User.create(email: params[:email], password: params[:password])
  36.     session[:user_id] = user.id
  37.     redirect to('/peeps')
  38.   end
  39. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top