sinatra で画像ファイルを扱うためのメモ

下策:直接アクションにベタ書き

[ユースケース] この画像1個だけでいいんです

   1  get '/logo.png' do
   2    content_type :png
   3    send_file "logo.png"
   4  end

中策:パラメータとブロック引数で処理

[ユースケース] images/* に画像が多くてアクション列挙してられない

   1  get '/images/:file.:ext' do |file, ext|
   2    content_type ext
   3    send_file "images/#{file}.#{ext}"
   4  end

上策:Rackに任せる

[ユースケース] 速度、効率的にフロントで捌きたい

   1  use Rack::Static, :urls => ["/images"], :root => "public"

これで Rails/Merb でおなじみの public/images/* を捌く事ができる

posted by Png maiha on Tue 28 Jul 2009 at 18:37
Contents
Sinatra で静的ファイル
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ