Does Ruby require "some-gem" to work in the console, not in Eclipse?

Well, I'm trying to run a simple web server through a 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 an 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 works is called the following:

 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 displays the expected Hello Rack code.

I am on Mac OS X 10.8, with ruby โ€‹โ€‹1.9.3 installed via rvm (this should be obvious). My rack package was installed with sudo gem install rack

So, as you can see, Eclipse is configured on the same ruby โ€‹โ€‹executable. Any suggestions would be very helpful!

+4
source share
2 answers

Line

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

means that he cannot find where you placed the gem in the rack. Reading on the Internet, I see again and again, using sudo does not seem to work. Try just installing it and see if it fixes it.

$ gem install rack (no sudo)

0
source

I ran into the same problem trying to require gems in Eclipse that it did not recognize, although everything seemed to be configured correctly (stones were installed, Eclipse was pointing to the correct Ruby interpreter, etc.).

I ended up adding the GEM_HOME and GEM_PATH to the Environment tab in the Debug / Run Configurations section.

More detailed answer here: fooobar.com/questions/891201 / ...

0
source

Source: https://habr.com/ru/post/1438637/


All Articles