34
Web Application Devlopment Webアプリ開発勉強会 #2 05.16.12

WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Embed Size (px)

Citation preview

Page 1: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Web Application Devlopment

Webアプリ開発勉強会 #2

05.16.12

Page 2: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Presented by U-moa

Page 3: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Agenda

1. 自己紹介タイム

2. ワークショップSinatraではじめるWebアプリ開発 #2

3. LT(あれば)

4. ふりかえり

Page 4: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Self-Introduction

自己紹介タイム

Page 5: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Self-Introduction

• 名前

• 所属

• 好きなこと、最近やっていることなどなど・・・

Page 6: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Workshop

ワークショップ

Page 7: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

WorkShop

今日の目標

データベースの検索とデータの保存が出来るようになる

Page 8: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Sinatraではじめる

Webアプリ開発 #2Sinatra is a DSL for quickly creating

web application in Ruby with minimal

effort:

Page 9: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

ウォームアップを兼ねて前回のおさらい

Page 10: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Hello, Sinatraを書こう

• 必要なライブラリをrequireしよう

• ‘/’にアクセスするとHello, Sinatra!! という文字列を返すようにしてみよう

Page 11: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Hello, Sinatraを書こう

1 require 'rubygems’

2 require 'sinatra’

3

4 get '/' do

5 'Hello, Sinatra!’

6 end

7

Page 12: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Hello, SinatraをHTMLにしよう

• HTMLのデータを返そう

• Formタグを使って文字列を送信できるようにしよう

Page 13: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

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

Page 14: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

投稿されたデータを表示しよう

• Formタグのactionで指定したURLを定義しよう (e.g. /toukou)

• params変数を使って投稿されたデータを表示してみよう

Page 15: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

投稿されたデータを表示しよう

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

Page 16: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

投稿をHTMLに埋め込もう

• 投稿データを配列に保存しよう

• 配列の中の投稿を<p>タグで囲もう

• そのデータをhtmlに埋め込もう

• 投稿後 ‘/’ にリダイレクトしよう

Page 17: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

投稿をHTMLに埋め込もう1 require 'rubygems’

2 require 'sinatra’

3

4 Messages = []

5 get '/' do

6 str = Messages.map do |msg|

7 "<p>#{msg}</p>”

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

26

27 post '/toukou' do

28 Messages << params[:message]

29

30 redirect '/’

31 end32

Page 18: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

思い出せましたか?

Page 19: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

それでは今日の内容に入ります

Page 20: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

前回のアプリ

Page 21: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

再起動するとデータが消える(T_T)

Page 22: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

そこで登場

データベース

Page 23: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

データベースとは

• たくさんのデータを整理して保存、取り出しをするための専用のソフトウェア

• 図書館の司書さんのような役割

要求を伝えると効率良く仕事をしてくれる

• 色んな種類があるがリレーショナルデータベース(RDBMS)というものが主流

Page 24: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

RDBMS

• データを表形式で管理する

• SQLという特殊な言語で操作する

• Excelを想像してみてください

Page 25: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

RDBMS

id name age type

1 ちひろ 22 human

2 ポチ 13 dog

... ... ... ...

familyテーブル

Page 26: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

SQLの例

id name age type

1 ちひろ 22 human

2 ポチ 13 dog

... ... ... ...

familyテーブル

select * from family where name=“ちひろ”;

Page 27: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

でもSQL覚えるのって面倒

Page 28: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

そこで登場

Sequel

Page 29: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

今日はSequelの勉強がメインです

Page 30: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Sequelとは

• Rubyからデータベースを操作するためのライブラリ

• SQLを使わずにDB操作が出来る!

Page 31: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

実際に使ってみましょう

Page 32: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Retrospectives

ふりかえり

Page 33: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Keep

Problem

Try

Page 34: WebAppDev勉強会 #2 at cafe? IKAGAWA DO

Keep = 良かったところ

Problem = 悪かったところ

Try = 次回の取り組み