4

After upgrading my Rails install to Rails 3 on OS X, I’ve had problems running my Rails 2.x development sites with Mongrel. WEBrick seems to work, but I really would like to have the nice output of Mongrel for debugging.

After running $ script/server I get this:

/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load': no such file to load -- mongrel_rails (MissingSourceFile)
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:49:in `gem_original_require'

So far, here’s what I’ve tried:

$ sudo gem update system
$ sudo gem update
$ sudo gem uninstall mongrel
$ sudo gem install mongrel --include-dependencies
$ which mongrel_rails

/usr/bin/mongrel_rails

$ mongrel_rails start

→ Success, but no stdout

$ which mongrel_rails

/usr/bin/mongrel_rails

$ rails _2.0.2_ test

→ Fresh application has same problem.

  • OS: OS X.6.x
  • Rails: 3.0.5 (problems are with Rails 2.x apps)
  • gem -v: 1.6.1
  • Mongrel: mongrel (1.1.5)

I’ve read EVERY Google result on "-- mongrel_rails (MissingSourceFile)"; there aren’t many.

Can anyone here tell me how to proceed in debugging this? Thanks!

UPDATE:

I’ve now tried installing older versions of the gem and specifying those in my Rails 2.x site’s config/environment.rb file. I’ve tried 1.1.5, 1.1.4, and 1.2.0pre.

None of these makes the slightest bit of difference.

Since the executable in in usr/bin I’m wondering if it’s a file ownership issue that got screwed up on my Rails 3 install and if one of the files isn’t getting my paths when it runs?

/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb is owned by admin / root, so that should be OK, right?

Could it be a problem with active_support!?

Here’s the code from dependencies.rb that’s throwing the error:

484 class Object
485   
486  alias_method :load_without_new_constant_marking, :load
487  
488  def load(file, *extras) #:nodoc:
489    Dependencies.new_constants_in(Object) { super(file, *extras) }
490  rescue Exception => exception  # errors from loading file
491     exception.blame_file! file
492     raise
493   end
...  

This is getting a file not found error, so it’s not looking where I know the file to be… Running mongrel_rails on command line works… Which mongrel_rails shows it in usr/bin, So what’s the problem?

Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
Techism
  • 534
  • 3
  • 11

8 Answers8

6

I have got the same problem and found the reason.

This happens because new version of RubyGems(1.6.2) does not add 'any_gem/bin' to ruby load path ($LOAD_PATH) when you require "any_gem".

For example in RubyGems version = 1.4.1 this works fine. After I require 'mongrel' I can see in load path next:

  • ...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/bin
  • ...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/lib
  • ...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/ext

With new version (1.6.2) I can see only:

  • ...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/lib
  • ...rvm/gems/ruby-1.8.7-p330/gems/mongrel-1.1.5/ext

That's why ruby cannot find 'mongrel_rails'.

4

You need to add "/usr/bin" to your load path. Perhaps something broke in it?

The best way to fix it is to add:

$:.push("/usr/bin/")

Somewhere before it breaks. Probably by itself in a config/preinitializer.rb file if you don't have one.

ROFISH
  • 78
  • 6
  • This worked perfectly and doesn't require my hack. Thank you! – Techism Apr 27 '11 at 21:40
  • 1
    For those having a hard time understanding this answer (as it is clearly the best one IMHO) this only involves adding the mentioned file to your app's config directory. One line, in the app, and everything runs fine locally and remote. – Techism Jun 03 '11 at 15:41
3

OK, here's ONE answer. I got mongrel to boot...but it's hacky, and doesn't solve the real problem...but at least for NOW I can get back to work on this project.

Here's what I did...YES..it's HACKY.

I edited the file throwing the error...dependencies.rb

I added a hook to call out the specific path to mongrel rails if that was the file it was trying to load.

def load(file, *extras) #:nodoc:

if file == "mongrel_rails"
  file ="/usr/bin/mongrel_rails"
end
Dependencies.new_constants_in(Object) { super(file, *extras) }
  rescue Exception => exception  # errors from loading file
  exception.blame_file! file
  raise
end

Again, I would really like to fix the underlying problem here...but this at least let me boot up.

Techism
  • 534
  • 3
  • 11
2

I would definitely look in to using RVM for running multiple gem versions simultaneously locally. I ran into a lot of quirks when I was attempting to run multiple versions like you are with sudo gem installs of everything.

Now it's as simple as rvm ree@my_app_1, and installing completely separate gems there, then switching to a different app and using rvm ree@my_app_2

ree is an alias for my install of ruby enterprise version, you could just as easily do it with ruby 1.9, 1.8.x, etc.

In each of my application's root directories I have a .rvmrc file that reads simply:

rvm ree@my_app --create

So that every time I switch to that directory, the gemset is automatically swapped for me.

nzifnab
  • 15,876
  • 3
  • 50
  • 65
  • A neat idea...but I'm really hoping to just fix the problem rather than install more stuff. If nothing else works, I may have to do this, but I'd rather avoid it since this is the only gem problem i'm having at the moment...Good to have a fallback though! – Techism Mar 08 '11 at 23:04
  • 1
    Yeah, it doesn't look like this is a problem that RVM will fix. – Techism Mar 10 '11 at 22:03
  • installing RVM is a good idea for other reasons, but it doesn't fix the problem. – Bryan Larsen Jun 24 '11 at 14:16
1

I wasn't aware there was Rails 3 mongrel support.

Most people use Thin (you can enable it by specifying gem 'thin' in your Gemfile then launching rails server thin / Webrick these days.

If this is for hosting then there's nginx and Passenger that'll help with that.

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • Again, my problem is not with rails 3, but starting my rails 2 apps, after having installed rails 3. – Techism Mar 10 '11 at 22:00
1

I ran into the same problem -- got my app going by running "mongrel_rails" from the project directory (instead of "script/server").

  • Yes, if you look at my post more carefully, you see that I did try that. It ran, but did not output to the console... – Techism Mar 21 '11 at 05:58
1

This is the thread where you are able to find the best answer to the mongrel_rails (MissingSourceFile) error. I just want to conclude here how I solved the problem, using stuff in this thread.

The simplest solution I could figure out how to do was to downgrade RubyGems by typing

(sudo) gem update --system 1.4.1

This lets me run the old 2.1.0 app (thanks Max Shytikov), but there's probably a lot of bugfixes that I'm missing by running the old version of rubygems. The error is probably a blunder by the mongrel gem developers (I guess).

Anyway if you just want to run your app using mongrel do it like this. If you insist on having the newest version of rubygems, you can just run your app with

script/server webrick

But I've found that webrick is a fair bit slower, so I prefer mongrel. If anyone has got a better solution for this problem, please let me know.

kalusn
  • 76
  • 4
  • If you read above, I did find several solutions that I preferred to running webrick: 1. Run "mongrel_rails start" from your project root. It will run, but you won't get the usual feedback that I find so nice during development. 2. See my "hack" that got er running. I just modified one rails file and added a hook to explicitly load mongrel via correct path. Code in my selected answer. – Techism Apr 19 '11 at 04:47
1

I ran into the same error. The fix is to add the mongrel "bin" directory to the $LOAD_PATH. Other posts describe how to do it by modifying source code, but since I share source code with other developers, I prefer to set the RUBYLIB environment variable instead.

$ export RUBYLIB=/Users/edwingo/.rvm/gems/ruby-1.8.7-p302@junction/gems/mongrel-1.1.5/bin

This causes the MRI ruby runtime to prepend that to the $LOAD_PATH.

Detailed explanation: MRI is unable to find 'mongrel_rails' because it is not on the $LOAD_PATH. I am using RVM and when I installed mongrel into a gemset, for some reason the $LOAD_PATH does not include the corresponding "bin" directory where 'mongrel_rails' lives. When not using RVM and after installing mongrel into the system gems, the "bin" directory does appear on the $LOAD_PATH so it all works.

Edwin Goei
  • 11
  • 2