More Related Content More from Nemoto Yusuke (9) 社内勉強会 - 書籍管理Webシステム6. Ruby :Web Server
• WEBrick
• Mongrel -> thin (<= Heroku推奨)
• Phusion Passenger (Standalone)
• Unicorn
old
new
13年8月19日月曜日
9. Rack実装
class App
def call(env)
case env[‘REQUEST_METHOD’]
when ‘GET’
[
200,
{ ‘Content-Type’ => ‘text/html’ },
[‘<html><head></head><body>hello</body></html>]
]
end
end
end
引数を1つ持つ
callメソッドを実装
•ステータスコード
•レスポンスヘッダ(Hash)
•レスポンスボディ(Array)
を返す
13年8月19日月曜日
16. ✕
テーブル
⃝
コレクション
{
"_id" : ObjectId("47cc67093475..."),
"username" : "bob",
"address" : {
"street" : "123 Main Street",
"city" : "Springfield",
"state" : "NY"
}
}
> db.users.find({"address.state" : "NY"})
User collection
13年8月19日月曜日
23. DB連携
• mongoid
• Object Document Mapper
• mongoid3の情報が少ない…
• 画像保存方法
• Base64文字列として保存
• 文字列として画像表示
class Book
include MongoID::Document
field :title, type: String
field :author, type: String
field :asin
validates_uniqueness_of :asin
end
13年8月19日月曜日
30. herokuでハマる③
• Webrick -> thin
• config.ru
• Procfile(foreman)
• modular style -> classic style
web: bundler exec config.ru -p $PORT
class App < Sinatra::Base
get ‘/’ do
‘hello world’
end
end
get ‘/’ do
‘hello world’
end
• なぜかmodularだとforeman動かない…
13年8月19日月曜日