I have the following declaration in my Gemfile
gem 'foo', :git => 'git#github.com:bar/foo.git'
After I run bundle install, it is able to retrieve the gem under the following folder
$ ls ~/.rvm/gems/ruby-1.9.3-p0#samples/bundler/gems/foo-4dc3d7bf8271
But using the gem in my program using require 'foo' and running it raises the following problem.
custom_require.rb:36:in `require': cannot load such file -- foo
(LoadError)
How do I resolve this?
EDIT
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/i686-linu
x
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/vendor_ruby/1.9.1
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/vendor_ruby/1.9.1/i686-li
nux
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/vendor_ruby
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/i686-linux
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/
custom_require.rb:36:in `require': cannot load such file -- foo (LoadError)
from /home/ec2-user/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.
9.1/rubygems/custom_require.rb:36:in `require'
Ensure that require 'bundler/setup' is called before you require any gem from your Gemfile. But in Rails case it should happen for sure, because rails server calls config/boot.rb, which contains such line.
Related
I have spent almost 8 hours on this and I know it's an easy fix.
I want to use this repository of the basecrm gem.
The problem: I don't know how to require/include the gem, neither locally as a cloned copy or as a regular "require gem_name" to find Leads
Ive download and put the gem files in /Users/username/Sites/basecrm/
and added the line below to my gem file.
gem 'basecrm', :git => 'git://github.com/basecrm/basecrm.git'
I ran "Bundle Install"
According to the Readme.md it says to call
require 'basecrm'
⌘ ~/Sites/basecrm/ irb
irb(main):001:0 require 'basecrm'
LoadError: cannot load such file -- basecrm
from /Users/username/.rbenv/versions/2.1.3/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/username/.rbenv/versions/2.1.3/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
from /Users/username/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'
irb(main):002:0session = BaseCrm::Session.new
NameError: uninitialized constant BaseCrm
from (irb):2
from /Users/username/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'
Any help is really appreciated. I am ready to tear my hair out on this.
If you use Gemfile you should run irb with bundler e.g. bundle exec irb and then require your gem require "basecrm"
I am running Rspec 3.0.0 and Ruby 1.9.3.
I was going through the test-first ruby tutorial: https://github.com/alexch/learn_ruby
When i go through the first excercise: 00_hello and run rake, I keep getting the following error:
c:\learn_ruby\00_hello>rake
(in c:/learn_ruby)
C:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:
36:in `require': cannot load such file -- spec_helper (LoadError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
I tried suggestions such as putting the following in the gemfile:
group :development, :test do gem 'rspec-rails', '~> 3.0.0.beta'
end
bundle install
bundle exec
rails generate rspec:install
that didn't help matters either, I also tried rspec --init, but I still keep getting the same error. I put require spec_helper in the hello_spec file too. Can someone please help me out?
$ bundle install
$ bundle exec
$ rails generate rspec:install
Should be ran from the terminal, not put inside the gemfile.
Run bundle in the terminal then try your rake command again.
We have a mail gem installed in our vendor/cache directory inside a Rails application.
The script is called "test" and is not inside the Rails application directory.
#! /usr/local/rvm/wrappers/ruby-1.9.3-p194/ruby
require 'date'
require 'fileutils'
require 'openssl'
require 'yaml'
require 'mail'
require 'dalli'
I get the following error when I execute this script from outside the Rails application.
/usr/local/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 -- mail (LoadError)
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
I simply re-installed these gems (mail, dalli) in the standard Ruby path and it worked, but that's not ideal.
What do we need to so that these installed gems are found when we try to run this script outside of a Rails app? In other words, how do we specify the path to these gems?
Be sure that your gem are all declared in your Gemfile:
gem 'mail'
If you don't want them to be loaded by default, and load them only when needed, you can use the require statement that you are already using, and in your Gemfile add :require => false:
gem 'mail', :require => false
When you call your script from outside your Rails environment, and want to load the gems, prefix your script by bundle exec:
bundle exec my_script.rb
If you need to run your script from another location than your rails's app root, you must run:
BUNDLE_GEMFILE=/path/to/your/app/Gemfile bundle exec your_script
Keep in mind though that this may cause path issues if your script or your gems are looking for file in the path of your rails app
When I add
require 'soundcloud'
in Rails and start the server using
rails server
I get
...rb:9:in `require': cannot load such file -- soundcloud (LoadError)
the same yields
=> true
in IRB.
I installed Ruby, Rails, etc following http://installrails.com/.
Any ideas what could be causing this?
Why don't you use Bundler?
Add to Gemfile:
gem 'soundcloud'
then run
bundle install
in the root of your project and it all should work automatically.
I have installed the gem : oauth2
I can load it in irb:
$ irb -rubygems
irb(main):001:0> require 'oauth2'
=> true
I have :
require 'rubygems'
in my code
and have set RUBYOPT :
export RUBYOPT=rubygems
while I still get the error:
LoadError in XXXController#login
no such file to load -- oauth2
Any help will be appreciated.
Did you specify the gem as a dependency in Rails?
If you are using Rails 3, make sure the gem is listed in your Gemfile and you successfully executed the command $ bundle install.