<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Shugo's Blog comments on Running Rails on mod_ruby</title>
    <link>http://blog.shugo.net/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Shugo's Blog comments</description>
    <item>
      <title>"Running Rails on mod_ruby" by shugo</title>
      <description>&lt;p&gt;I implemented &lt;a href="http://svn.modruby.net/repos/mod_ruby/trunk/lib/apache/rails-dispatcher.rb"&gt;Apache::RailsDispatcher&lt;/a&gt; to run Rails applications on mod_ruby.
You have to use &lt;a href="http://svn.modruby.net/repos/mod_ruby/trunk/"&gt;the SVN HEAD version of mod_ruby&lt;/a&gt; to use it.&lt;/p&gt;

&lt;p&gt;Apache::RailsDispatcher can run multiple applications in the same process.
It works like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;require&lt;/code&gt; loads libraries into the top level, and they are shared with 
all applications.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;require_dependency&lt;/code&gt; loads libraries into an anonymous module for each
application.&lt;/li&gt;
&lt;li&gt;In the development environment, the anonymous module is orphaned
on each request. So &lt;code&gt;required_dependency&lt;/code&gt; loads libraries every time.&lt;/li&gt;
&lt;li&gt;In the production environment, the same anonymous module is used for
the same application. So &lt;code&gt;required_dependency&lt;/code&gt; loads libraries only at once.&lt;/li&gt;
&lt;li&gt;Rails configurations such as &lt;code&gt;ActiveRecord::Base.colorize_logging&lt;/code&gt; are
reset on each request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This hack is just a workaround until YARV supports multiple VM instances.
We can get it in the near future, I hope.&lt;/p&gt;

&lt;p&gt;To use Apache::RailsDispatcher, you have to write the following
configuration in httpd.conf.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;RubySafeLevel 0
# If you use RubyGem
# RubyRequire rubygems
RubyRequire apache/rails-dispatcher
RubyTransHandler Apache::RailsDispatcher.instance
&amp;lt;Location /appname&amp;gt;
  SetHandler ruby-object
  RubyHandler Apache::RailsDispatcher.instance
  RubyOption rails_uri_root /appname
  RubyOption rails_root /path/to/rails/root
  RubyOption rails_env production
&amp;lt;/Location&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Please note that you can't override exinting classes like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Array
  def cycle()
    self.each_with_index {|o, i| yield(o, %w(odd even)[i % 2])}
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You should prepend Object:: to the class name:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Object::Array
  def cycle()
    self.each_with_index {|o, i| yield(o, %w(odd even)[i % 2])}
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This behaivour is same as Kernel.load(filename, true).
If you don't like this, please convince Matz to change it.&lt;/p&gt;

</description>
      <pubDate>Wed,  3 Aug 2005 14:34:00 JST</pubDate>
      <guid>&lt;a href="/articles/2005/08/03/running-rails-on-mod_ruby"&gt;Running Rails on mod_ruby&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2005/08/03/running-rails-on-mod_ruby"&gt;Running Rails on mod_ruby&lt;/a&gt;</link>
    </item>
  </channel>
</rss>

