Rails 3 and Mongrel
Today, the Rails team finally released the first beta of Rails 3. Trying to play around with it, I experienced a very annoying problem with mongrel:
Per default, Rails seems to only work with the gems listed in its Gemfile, which means that it starts using webrick.
I wanted it to use mongrel, like Rails 2 does and added gem "mongrel" to my gemfile which resulted in rails server just freezing.
The cuplrit was some of the weirdest piece of code I’ve ever seen, mongrel’s Mongrel::Gems.require function:
def require(library, version = nil)
begin
Kernel.require library
rescue LoadError, RuntimeError => e
begin
# ActiveSupport breaks ‘require’ by making it always return a true value
Kernel.require ‘rubygems’
version ? gem(library, version) : gem(library)
retry
rescue Gem::LoadError, LoadError, RuntimeError
# puts "** #{library.inspect} could not be loaded" unless library == "mongrel_experimental"
end
end
end
An infinite loop with the only way out being an exception that never got thrown!
This madness was called from mongrel.rb:
$LOAD_PATH.unshift ‘projects/mongrel_experimental/lib/’
Mongrel::Gems.require ‘mongrel_experimental’, ">=#{Mongrel::Const::MONGREL_VERSION}"
Removing these two lines solved the issue. That would have meant patching my gems however, and that smells like something you should not do. The final solution was simple and posted in the comments of the Rails 3 Beta announcement by Juanma Cervera. I just needed to add 3 more lines to my Gemfile:
gem "mongrel"
gem "cgi_multipart_eof_fix"
gem "fastthread"
gem "mongrel_experimental"

12 Comments for 'Rails 3 and Mongrel'
Thanks very much. Helped me out no end!
Uh, isn’t that 4 lines?
I was able to get it working with 3, however, leaving out “mongrel_experimental”
Hi Jan,
do you use mongrel for production or just for development as a faster starting local server?
Thanks, this got me going!
If you’re running Rails3 on Ruby 1.9.2, the suggestion doesn’t work because Mongrel fails to install. However, these lines in GemFile do work:
gem “mongrel”, “1.2.0.pre2″
gem “cgi_multipart_eof_fix”
gem “fastthread”
Just for development. All production systems I’ve worked on are using REE 1.8.7 and Passenger.
I haven’t deployed any new apps this year since I’m working on a non-rails project since March.
[...] [...]
[...] Rails 3 and Mongrel [...]
Hi Jan
I got it working with just :
gem ‘mongrel’, ’1.2.0.pre2′
gem ‘cgi_multipart_eof_fix’
Got error “make not a command” when trying “fastthread” (I’m on windows), but it seems to work without it.
I really like these short concise technical posts, and they say ‘middle take’ blogging is dying (see http://z6.co.uk/tj).
Ed Ruder’s comment was useful for me because I am using ruby 1.9.2 and rails 3. (note: copy and paste on text doesn’t work because of the way the quotation marks are formatted)
Thanks to you both
Thanx a lot!!!! Stupid rails errors like that make studying process very difficult!!!
I know that mongrel is not compatible with Rails 3. So I can’t run mongrel_rails start in Rails 3. If I do so, i will get dispather error. I have to make mongrel the default server and do
script/rails server -p 3001
Then it works. However, my question is that mongrel has other options like –prefix, how do i make mongrel knows about this option under script/rails? I try to use
script/rails server -p 3001 –prefix /my_app
This doesn’t work as –prefix is not a known conf to script/rails server. Could you help?Thanks a lot.
Hm, you could try starting mongrel with the mongrel executable and have it run rails as a rack app.
I haven’t tried that though, just a guess.
Write a comment
Comment Links: Feed – Trackback