Bubble

I've been chasing my tail on this issue for a couple of days and more than ever. I am running Rails 3.1, Ruby 1.9, Gem 1.8.15, Linux RHEL 4.

The simplified problem is that ruby ​​'require' (and rails) cannot find all the jewels that my application needs. And it seems that gems cannot find a gem name other than * .rb. For example, "require" sass "finds sass.rb. But" require "therubyracer" "cannot find v8.rb inside lib. There is no file called 'therubyracer.rb'. The same with 'therubyrhino" - no no' therubyrhino.rb ', but in lib there is "rhino.rb".

Installing the package does not cause an error, even if these gems are in my gemfile.

Here is an example:

First, to demonstrate the stone, set:

>locate 'rhino.rb' /usr/local/lib/ruby/gems/1.9.1/gems/therubyrhino-1.73.1/lib/rhino.rb /usr/local/lib/ruby/gems/1.9.1/gems/gems/therubyrhino-1.73.1/lib/rhino.rb 

Despite the fact that "therubyrhino" is installed, and on the path and the running package, "gem" can not find it. And this gem is in

the same path as "sass", below, which he can find. Here is the error:

 gem which 'therubyrhino' ERROR: Can't find ruby library file or shared library therubyrhino 

Note that the gem can find the rhino.rb file inside the gem, so the path should work.

 >gem which rhino /usr/local/lib/ruby/gems/1.9.1/gems/therubyrhino-1.73.1/lib/rhino.rb 

Claim don't like rhino.rb:

 ruby -rubygems -e 'require "rhino"' /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in ` require': no such file to load -- java (LoadError) 

And he cannot find a stone by name.

  ruby -rubygems -e 'require "therubyrhino"' /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in ` require': no such file to load -- therubyrhino (LoadError) from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in ` require' 

But, as I said, "therubyrhino" works in my Gemfile Bundle.

Here is my gem route, which I manually configure for verification:

 >export GEM_PATH=/usr/local/lib/ruby/gems/1.9.1:/usr/local/lib/ruby/gems/1.9.1/gems:/usr/local/lib/ruby/gems/1.9.1/gems/gem >gem env ... RubyGems Environment: - RUBYGEMS VERSION: 1.8.15 - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [i686-linux] - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1 - RUBY EXECUTABLE: /usr/local/bin/ruby - EXECUTABLE DIRECTORY: /usr/local/bin - RUBYGEMS PLATFORMS: - ruby - x86-linux - GEM PATHS: - /usr/local/lib/ruby/gems/1.9.1 - /usr/local/lib/ruby/gems/1.9.1/gems - /usr/local/lib/ruby/gems/1.9.1/gems/gem - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://rubygems.org/ 

And finally, here is the case when life is good and requires work. Everything is fine and the name prefix gem = lib name (... / sass / lib / sass.rb). First we see that the sass stone is installed:

  >locate sass.rb /usr/local/lib/ruby/gems/1.9.1/gems/sass-3.1.14/lib/sass.rb /usr/local/lib/ruby/gems/1.9.1/gems/haml-3.1.4/vendor/sass/lib/sass.rb /usr/local/lib/ruby/gems/1.9.1/gems/haml-3.1.4/lib/sass.rb 

Can a gem find it? Yes.

  >gem which sass /usr/local/lib/ruby/gems/1.9.1/gems/haml-3.1.4/lib/sass.rb 

And does ruby ​​work require? Yes.

  >ruby -rubygems -e 'require "sass"' (no error) 

Thanks for your help.

+4
source share
2 answers

Before you execute require , you need to load the gem using the gem command. For instance:

 $ irb 1.9.3p0 :001 > gem 'therubyracer' => true 1.9.3p0 :002 > require 'v8' => true 
+2
source

If you have therubyracer in your Gemfile , then all you need to do in your application is require 'v8' . Or you can specify lib in your Gemfile :

 gem "therubyracer", :require => 'v8' 

If you use Bundler.require , the above line will automatically call require 'v8' .

Please note that therubyrhino for jruby only; you cannot use it with C Ruby (MRI).

+2
source

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


All Articles