Skip to content

Instantly share code, notes, and snippets.

@kikiriko200
Created March 25, 2019 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikiriko200/a9abcb156c74393b29c371a20caba8ff to your computer and use it in GitHub Desktop.
Save kikiriko200/a9abcb156c74393b29c371a20caba8ff to your computer and use it in GitHub Desktop.
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