4

Well, I'm trying to run a simple web server through "rack". So this is my program:

require 'rubygems'
require 'rack'

class HelloWorld
  def call(env)
    [200, {"Content-Type" => "text/html"}, ["Hello Rack!"]]
  end
end

Rack::Handler::Mongrel.run HelloWorld.new, :Port => 9292

If I run it in the console, it works fine. If I run it in Eclipse, it ends up with error:

/Users/MY_SUPER_SECRET_USER/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rack (LoadError)
    from /Users/MY_SUPER_SECRET_USER/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/MY_SUPER_SECRET_USER/Sites/service/service.rb:2:in `<main>'

The one that is working is called like this:

MY_SUPER_SECRET_USER@MacBook-Pro:~/Sites/service $ which ruby
/Users/MY_SUPER_SECRET_USER/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
MY_SUPER_SECRET_USER@MacBook-Pro:~/Sites/service $ ruby service.rb

Then when I try to open localhost:9292 it shows the expected "Hello Rack" code.

I'm on Mac OS X 10.8, with ruby 1.9.3 installed through rvm (this must be obvious). My "rack" package has been installed with sudo gem install rack

So as you can see, the Eclipse is configured with the very same ruby executable. Any suggestions will be of great help!

ddinchev
  • 33,683
  • 28
  • 88
  • 133
  • Make sure that Eclipse is running on same Ruby environment as a console. Sounds to me that eclipse is using one Ruby environment and Eclipse the other. That would be that Eclipse should be running ruby-1.9.3-p194. – Haris Krajina Oct 12 '12 at 13:14
  • Well, as you can see from the Eclipse error log - it is running ruby-1.9.3-p194 :( – ddinchev Oct 12 '12 at 13:16
  • Oh mixed it up, ruby environment was my bet try running `puts system('gem list')` from ruby code via eclipse to see if you can see gems. If output is different from one in your console, than it is different ruby env. – Haris Krajina Oct 12 '12 at 13:18

2 Answers2

0

The line

custom_require.rb:36:in `require': cannot load such file -- rack (LoadError)

means it can't find where you installed the rack gem. Reading around the internet, I see again and again using sudo doesn't seem to work. Try just installing it and see if that fixes it.

$ gem install rack (no sudo)

AJcodez
  • 31,780
  • 20
  • 84
  • 118
0

I ran into this same problem, trying to require gems in Eclipse which it wasn't recognizing, even though everything seemed to be configured correctly (the gems were installed, Eclipse was pointing at the right Ruby interpreter, etc).

I ended up making it work by adding GEM_HOME and GEM_PATH variables to the Environment tab of Debug/Run Configurations.

More detailed answer here: https://stackoverflow.com/a/28419300/525338

Community
  • 1
  • 1
Dmitri Zagidulin
  • 1,117
  • 9
  • 23