diff --git a/comment_db b/comment_db new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/comment_db diff --git a/index.haml b/index.haml new file mode 100644 index 0000000..f53ca62 --- /dev/null +++ b/index.haml @@ -0,0 +1,38 @@ +!!! + +%html{:lang => "ja"} + %head + %title= @title + %meta{:content => "text/html", :"http-equiv" => "Content-Type", :charset => "utf-8"} + + %body + %h1 #{@title} + + %h2 Comment Write + %form{:method => "POST", :action => '/request_print'} + %input{:type => "hidden", :name => "_method", :value => "PUT"} + %table + %tr + %td Your Name + %td + %input{:type => "text", :name => "name"} + %tr + %td Title + %td + %input{:type => "text", :name => "title"} + %tr + %td Comment + %td + %input{:type => "text", :name => "message"} + %tr + %td + %td + %input{:type => "submit", :value => "コメントする"} + %input{:type => "reset", :value => "内容をリセットする"} + + %h2 Comments List + %table + - @comments_data.each do |comment| + %tr + - comment.each do |element| +%td= element diff --git a/request_print.haml b/request_print.haml new file mode 100644 index 0000000..123bb66 --- /dev/null +++ b/request_print.haml @@ -0,0 +1,16 @@ +!!! + +%html{:lang => "ja"} + %head + %title Request Print + %body + %p リクエストのHTTPメソッドと実行パス + %p + = "method = #{@request_method}" + = "url = #{@request_url}" + = "path = #{@request_path}" + %p 入力フォームのテキストボックスから入力されたデータ + %p + = "TextBox(name) = #{@name}" + = "TextBox(title) = #{@title}" += "TextBox(message) = #{@message}" diff --git a/sinatra_form00.rb b/sinatra_form00.rb new file mode 100644 index 0000000..0a3405f --- /dev/null +++ b/sinatra_form00.rb @@ -0,0 +1,27 @@ +#!/usr/bin/ruby +#-*- coding: utf-8 -*- + +require 'sinatra' +require 'erb' + +get '/post' do + @name = "" + erb :index +end + +post '/' do + @name = @params[:name] + erb :index +end + +__END__ +@@index + + +
+ + +
+ + + diff --git a/sinatra_form01.rb b/sinatra_form01.rb new file mode 100644 index 0000000..77c242d --- /dev/null +++ b/sinatra_form01.rb @@ -0,0 +1,32 @@ +#!/usr/bin/ruby +# encoding: utf-8 + +# File Name: sinatra_start.rb +# Create Day is 2015/05/20 +# Last Update Day is 2015/05/20 + +# Gem List +gem 'tilt', '2.0.8' +# Require List +require 'sinatra' +# sinatra reloader is classic type +require 'sinatra/reloader' if development? +require 'haml' +require 'tilt' +require 'csv' + +# 外部エンコーディングを変更 +Encoding.default_external = "UTF-8" + +get '/' do + @title = "Welcom to Sinatra BBS!!" + @comments_data = CSV.read("db/comment_db.csv") + haml :index +end + +put '/request_print' do + CSV.open("db/comment_db.csv", "a") do |csv| + csv << [params[:name], params[:title], params[:message]] + end +redirect '/' +end diff --git a/sinatra_start.rb b/sinatra_start.rb new file mode 100644 index 0000000..4de85bd --- /dev/null +++ b/sinatra_start.rb @@ -0,0 +1,37 @@ +#!/usr/bin/ruby +#-*- coding: utf-8 -*- + +require 'sinatra' + +get '/' do + 'Hello, world!' +end + +get '/user/:name' do + 'Hello, #{params[:name]}' +end + +get %r|/group/([a-zA-Z0-9]+)| do |group| + 'Hello, G:#{group}!' +end + +get '/time' do + erb(:time) +end + +post '/login' do + "Onamae: #{params[:onamae]}" + + "Password: #{params[:pswd]}" +end + + +n = 0 +get '/number' do + n += 1 + 'Hello, world! - ' + n.to_s + '人目のお客様!!' +end + +get '/index.html' do + 'Hello, world! kuma!' +end +