Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'bundler/setup'
Bundler.require
require 'sinatra/reloader' if development?
require 'sinatra/activerecord'
require './models'
helpers do
include Rack::Utils
alias_method :h,:escape_html
end
before do
@sitename = '高校生が作る奈良観光サイト'
end
get '/comment' do
@histories = Post.all
erb :comment
end
get '/' do
erb :index
end
get '/secondpage' do
erb :secondpage
end
get '/community' do
erb :community
end
get '/comment' do
erb :comment
end
post '/create' do
name = params[:name]
body = params[:body]
unless name.empty? && body.empty?
@post = Post.create({
name: params[:name],
body: params[:body]
})
redirect'/comment'
else
redirect'/comment'
# errorページに飛ばしてもいいかも
end
end
not_found do
throw(:halt, [404, "404 Not Found"])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.