More Related Content Similar to WebAppDev勉強会 #2 at cafe? IKAGAWA DO (20) WebAppDev勉強会 #2 at cafe? IKAGAWA DO3. Agenda
1. 自己紹介タイム
2. ワークショップ
SinatraではじめるWebアプリ開発 #2
3. LT(あれば)
4. ふりかえり
7. WorkShop
今日の目標
データベースの検索と
データの保存が出来るようになる
13. Hello, SinatraをHTMLにしよう
1 require ‘rubygems’
2 require 'sinatra’
3
4 get '/' do
5 <<-EOS
6 <html>
7 <head>
8 <title>Hello, Sinatra!!</title>
9 </head>
10 <body>
11 <h1>My First Web Application.</h1>
12 <form action="/toukou" method="post">
13 <div><input type="text" name="message"></div>
14 <div><input type="submit" value="submit"></div>
15 </form>
16 <div>#{str}</div>
17 </body>
18 </html>
19 EOS
20 end
15. 投稿されたデータを表示しよう
1 require 'rubygems’
2 require 'sinatra’
3
4 get '/' do
5 # 省略
6 end
7
8 post '/toukou' do
9 params[:message]
10 # :messageはinputタグのname要素で指定したもの
11 end
17. 投稿をHTMLに埋め込もう
1 require 'rubygems’ 26
2 require 'sinatra’ 27 post '/toukou' do
3 28 Messages << params[:message]
4 Messages = [] 29
5 get '/' do 30 redirect '/’
6 str = Messages.map do |msg| 31 end
7 "<p>#{msg}</p>” 32
8 end.join("")
9
10 <<-EOS
11 <html>
12 <head>
13 <title>Hello, Sinatra!!</title>
14 </head>
15 <body>
16 <h1>My First Web Application.</h1>
17 <form action="/toukou" method="post">
18 <div><input type="text" name="message"></div>
19 <div><input type="submit" value="submit"></div>
20 </form>
21 <div>#{str}</div>
22 </body>
23 </html>
24 EOS
25 end
25. RDBMS
id name age type
1 ちひろ 22 human
2 ポチ 13 dog
... ... ... ...
familyテーブル
26. SQLの例
id name age type
1 ちひろ 22 human
2 ポチ 13 dog
... ... ... ...
familyテーブル
select * from family where name=“ちひろ”;