Running Rails on mod_ruby
Posted by Shugo Maeda Wed, 03 Aug 2005 05:34:00 GMT
I implemented Apache::RailsDispatcher to run Rails applications on mod_ruby. You have to use the SVN HEAD version of mod_ruby to use it.
Apache::RailsDispatcher can run multiple applications in the same process. It works like this:
requireloads libraries into the top level, and they are shared with all applications.require_dependencyloads libraries into an anonymous module for each application.- In the development environment, the anonymous module is orphaned
on each request. So
required_dependencyloads libraries every time. - In the production environment, the same anonymous module is used for
the same application. So
required_dependencyloads libraries only at once. - Rails configurations such as
ActiveRecord::Base.colorize_loggingare reset on each request.
This hack is just a workaround until YARV supports multiple VM instances. We can get it in the near future, I hope.
To use Apache::RailsDispatcher, you have to write the following configuration in httpd.conf.
RubySafeLevel 0
# If you use RubyGem
# RubyRequire rubygems
RubyRequire apache/rails-dispatcher
RubyTransHandler Apache::RailsDispatcher.instance
<Location /appname>
SetHandler ruby-object
RubyHandler Apache::RailsDispatcher.instance
RubyOption rails_uri_root /appname
RubyOption rails_root /path/to/rails/root
RubyOption rails_env production
</Location>
Please note that you can't override exinting classes like this:
class Array
def cycle()
self.each_with_index {|o, i| yield(o, %w(odd even)[i % 2])}
end
end
You should prepend Object:: to the class name:
class Object::Array
def cycle()
self.each_with_index {|o, i| yield(o, %w(odd even)[i % 2])}
end
end
This behaivour is same as Kernel.load(filename, true). If you don't like this, please convince Matz to change it.
Other posts about this post.
This post has been discussed on the following web sites / blogs. If you wish to trackback to this post please use the following trackback address: http://blog.shugo.net/articles/trackback/2
Spread the word.
Shugo's Blog supports RSS (Real Simple Syndication), and Trackbacks from other blogs.
Your Comments.
Leave your own response