A jak se mod_ruby používá? V konfiguraci apache jsme uvedli že mod_ruby rozeznává jako své soubory s příponou .rbx. Tyto jsou výkonné ruby soubory. Musí být čitelné a spustitelné pro apache
$ ls -l /var/www/ruby/modruby/hello.rbx
-rwxr-x--- 1 radek www-data 21 říj 27 20:27 /var/www/ruby/modruby/hello.rbxUkážeme si jednoduchou stránku
1 # $Id: handle1.rbx,v 1.1 2003/10/28 16:02:24 radek Exp $
2 # $Source: /home/radek/cvs/ruby-book/example/modruby/handle1.rbx,v $
3 r = Apache.request
4 r.content_type = 'text/html'
5 r.send_http_header
6 exit(Apache::OK) if r.header_only?
7
8 puts("The time at the tone is: #{Time.new()}")
9 Použít informalexample/programlisting/inlinemediaobject/imageobject
1 # $Id: headers.rbx,v 1.1 2003/10/28 16:02:24 radek Exp $
2 # $Source: /home/radek/cvs/ruby-book/example/modruby/headers.rbx,v $
3 r = Apache.request
4 r.content_type = 'text/html'
5 r.send_http_header
6 exit(Apache::OK) if r.header_only?
7
8 puts '<table border="1">'
9 r.headers_in.each_key do |header|
10 puts "<tr><td>#{header}</td><td>#{r.headers_in[header]}</td></tr>"
11 end
12 puts '</table>'
13
1 #$Id: request.rbx,v 1.1 2003/10/28 16:02:24 radek Exp $
2
3 r = Apache.request
4 r.content_type = 'text/html'
5 r.content_encoding = 'iso-8859-2'
6 r.send_http_header
7 exit(Apache::OK) if r.header_only?
8
9 r.puts '<h1>Apache.request</h1>'
10
11 r.puts <<-EOS
12 <h2>request.methods</h2>
13 <p>Seznam metod objektu <tt>Apache.request</tt>:<br/>
14 #{r.methods.sort.collect{|m| "<tt>#{r.escape_html(m)}</tt>"}.join ", "}
15 </p>
16 EOS
17
18 puts <<-EOS
19 <h2>request[]</h2>
20 <table border="1">
21 <tr><th colspan="2">Hodnoty Apache.request[]</th><tr>
22 <tr><th>key</th><th>value</th></tr>
23 EOS
24 r.each_key do |k|
25 puts "<tr><td>#{k}</td><td>#{r[k]}</td></tr>"
26 end
27 puts <<-EOS
28 </table>
29 EOS
30
31 puts <<EOS
32 <h2>Hodnoty n�kter�ch atribut� objektu <tt>Apache.request</tt></h2>
33 <table border="1">
34 <tr><th>atribut</th><th>hodnota</th></tr>
35 <tr><th>args</th><td><tt>#{r.escape_html(r.args)}</tt></td></tr>
36 <tr><th>content_encoding</th><td><tt>#{r.content_encoding.to_s}</tt></td></tr>
37 </table>
38 EOS
39 # <tr><th>content_encoding</th><td><tt>#{r.escape_html(r.content_encoding)}</tt></td></tr>
40
41 puts '<h2>request</h2>'
42 puts '<table border="1">'
43 r.headers_in.each_key do |header|
44 puts "<tr><td>#{header}</td><td>#{r.headers_in[header]}</td></tr>"
45 end
46 puts '</table>'
47
