1 / 18

MySQL/Ruby, ERB, mod_ruby を使った CGI の実例

MySQL/Ruby, ERB, mod_ruby を使った CGI の実例. Kazuhiro Yoshida moriq@moriq.com. KANSAI OPEN SOURCE+FREEWARE 2003. Ruby 活用事例. 実務で使えるツールを Ruby で作成 Web ブラウザや携帯電話からアクセス. わははネットの携帯サイト. 妊婦さんから小学校入学前までのお子さんを持つ親を対象に 地域別のイベント情報・子育て情報を配信 メールで URL を返して携帯端末で開いてもらう. (株)岩佐佛喜堂のツール. 勤務表 ( 出欠表 ) 在庫・販売管理

Download Presentation

MySQL/Ruby, ERB, mod_ruby を使った CGI の実例

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MySQL/Ruby, ERB, mod_rubyを使ったCGIの実例 Kazuhiro Yoshida moriq@moriq.com KANSAI OPEN SOURCE+FREEWARE 2003

  2. Ruby活用事例 • 実務で使えるツールをRubyで作成 • Webブラウザや携帯電話からアクセス

  3. わははネットの携帯サイト • 妊婦さんから小学校入学前までのお子さんを持つ親を対象に • 地域別のイベント情報・子育て情報を配信 • メールでURLを返して携帯端末で開いてもらう

  4. (株)岩佐佛喜堂のツール • 勤務表(出欠表) • 在庫・販売管理 • 配達予定表

  5. 使用するライブラリ • MySQL/Ruby • ERB • mod_ruby

  6. MySQL/Ruby • by とみたさん • Ruby/MySQL • (Ruby/DBI) • デフォルトcharsetをShift JISに • メッセージカタログもShift JISで用意

  7. ERB • eRuby 前田さん↓使いやすさ • ERB 咳さん↓速度 • erbscanmoonwolfさん

  8. mod_ruby • 仕組み apache/ruby-run.rb • 結果として速度とメモリに影響 • グローバル変数の奇妙な振る舞い [実例]

  9. apache/ruby-run.rb: … Apache.chdir_file(filename) load(filename, true) …

  10. app1.rbx: $gv = 0 def inc_gv $gv += 1 end 5.times{inc_gv} … print $gv

  11. app2.rbx: require './lib2.rb' 5.times{inc_gv} … print gv lib2.rb: $gv = 0 def inc_gv $gv += 1 end def gv $gv end

  12. app3.rbx: require './lib3.rb' foo = Foo.new 5.times{foo.inc_iv} … print foo.iv lib3.rb: class Foo def initialize @iv = 0 end def inc_iv @iv += 1 end attr :iv end

  13. 半角カナ • 上手に付き合えば問題ない • どこで化ける?→ nkfライブラリとの相性 [実例]

  14. require 'erb' class Foo include ERB::Util include ERB::DefMethod dir = File.dirname( __FILE__ ) def_erb_method( :output, File.join(dir, 'foo.erb') ) end

  15. require 'cgi' cgi = CGI.new header = { 'type' => 'text/html', # 'charset' => 'shift_jis', 'Cache-Control' => 'no-cache', } foo = Foo.new cgi.out( header ){ foo.output }

  16. cgi.rb: def out(options = "text/html") … case options["charset"] when /shift_jis/ni content = NKF::nkf('-s', content) …

  17. 絵文字 • 単純な置換で済む • 各キャリアに対応 → HTTP_USER_AGENT • cgi.user_agent • httpd.conf: RewriteConf %{HTTP_USER_AGENT} (J-PHONE|UP\.Browser)

  18. まとめ • Rubyで実務アプリを作れる • Rubyで携帯サイトを作れる • Ruby以前に文字コード, MySQL, apacheについて調べることが大切 • 効率は後から考えればよい

More Related