Created
March 25, 2019 08:11
-
-
Save kikiriko200/a9abcb156c74393b29c371a20caba8ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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