LoadError on require yajl - ruby-on-rails

I have installed yajl, libyajl-dev, and the yajl-ruby gem on a ubuntu 10.04 installation.
I added the gem to a 2.3.8 ruby on rails installation since the release notes for 2.3.6 indicated that yajl would be used if present in the system. Rails bails with an error message along the lines of 'unable to load yajl-ruby' so I thought I would see what is happening in an irb session. This is what happens:
$ dpkg -l | grep yajl
ii libyajl-dev 1.0.8-1 Yet Another JSON Library - development files
ii libyajl1 1.0.8-1 Yet Another JSON Library
ii yajl-tools 1.0.8-1 Yet Another JSON Library - tools
$ gem list | grep yajl
yajl-ruby (0.7.6)
$ irb
> require 'yajl'
LoadError: no such file to load -- yajl
from (irb):1:in `require'
from (irb):1
from :0
> require 'yajl/gzip'
LoadError: no such file to load -- yajl/gzip
from (irb):2:in `require'
from (irb):2
from :0
> require 'yajl-ruby'
LoadError: no such file to load -- yajl-ruby
from (irb):3:in `require'
from (irb):3
from :0
I cannot find anyone else with this problem after spending a while searching for this issue. Anyone have any idea what is going on?

Use the gem instead sudo gem install yajl-ruby
Then just use it like any other gem in your ruby script
require 'rubygems'
require 'yajl'
json = File.new('test.json', 'r')
parser = Yajl::Parser.new
hash = parser.parse(json)

Related

cannot load such file -- aws-sdk-elastictranscoder>

I am currently referencing code from the AWS Documentation Ruby Example JobStatusNotificationSample.rb
My error comes from the first line: require 'aws-sdk-elastictranscoder'
Which says that I am not able to load this file. In my code, I am already using
require 'aws-sdk-s3'
require 'aws-sdk-sqs'
with no previous issues. I have tried to add in require 'aws-sdk-core' but that did not change the error.
It is my first time working with an AWS implementation on Ruby.
I have an error below when I m using Ruby SDK gem v3.
Traceback (most recent call last):
2: from test_sdk.rb:1:in `<main>'
1: from /home/xxx/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
/home/xxx/.rbenv/versions/2.7.6/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- aws-sdk-s3 (LoadError)
My solution:
In your terminal install aws-sdk
gem install aws-sdk
Then in your ruby file test_sdk.rb, add these in the top of the file
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk-s3'
Then run ruby test_sdk.rb works for my case.
Reference link:
https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingTheMPRubyAPI.html

Ruby Script API That Requires a gem

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"

Load Error when requiring 'twitter-text' gem

I am trying to use the twitter-text-rb (https://github.com/twitter/twitter-text-rb) in my Rails 3 app.
I installed it using bundler and my gemfile - seemingly successfully - but when I try and include its autolink function in my Application Helper, like this:
require 'twitter-text'
module ApplicationHelper
include Twitter::Autolink
end
I get this error in the browser when I try to load the root of the app:
Routing Error
uninitialized constant Twitter::Autolink Try running rake routes for
more information on available routes.
I've followed these Troubleshooting Questions within the Ruby Gems manual but it doesn't seem to be either of the two likely issues that they suggest under "Why does require 'some_gem' fail?".
Here's the extract from when I followed their instructions from the root of my app using terminal:
manager$ gem list twitter-text
*** LOCAL GEMS ***
twitter-text (1.5.0)
manager$ ruby -rubygems -e 'require "twitter-text"'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `gem_original_require': no such file to load -- twitter-text (LoadError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `require'
from -e:1
manager$ gem contents --no-prefix twitter-text | grep lib
lib/twitter-text.rb
lib/twitter-text/autolink.rb
lib/twitter-text/deprecation.rb
lib/twitter-text/extractor.rb
lib/twitter-text/hit_highlighter.rb
lib/twitter-text/regex.rb
lib/twitter-text/rewriter.rb
lib/twitter-text/unicode.rb
lib/twitter-text/validation.rb
manager$ ruby -rubygems -e 'require "twitter-text"'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `gem_original_require': no such file to load -- twitter-text (LoadError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `require'
from -e:1
manager$ which ruby
/usr/bin/ruby
manager$ gem env | grep 'RUBY EXECUTABLE'
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
I'm using and handful of other gems in the app and haven't run into similar problems before.
I'm at a loss as what to try next. I'm pretty new to Ruby/Rails (and programming in general for that matter!) so any help would be much appreciated.
thanks,
Matt
I've now got this gem working and removed the Load Error (although I can't say for sure what went right).
I installed RVM and tried my app and the twitter_gem using Ruby 1.9.2 and Rails 3.2.3. I was previously using the system default Ruby - 1.8.7 - and Rails 3.2.3. The gem was loaded correctly and worked perfectly.
So it seems like the problem was with the gem working on the earlier version of Ruby or RVM's gemsets helped the app to load the gem correctly.

Unable to load gem during runtime - cannot load such file

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.

"uninitialized constant Gem" or "Rails" when starting Rails 2 app

I have an application using Rails 2.3.4 which I'm trying to run. No matter how I start it, by using script/console or script/ferret_server, it always boils down to the same error:
uninitialized constant Gem
When I search online, I only find people who has a similar problem finding something inside of the Gem class. But in my case, Gem is just not there at all.
I am running Ruby on Ubuntu. I tried using the version of Ruby that came with APT and a more recent one with RVM. Nothing helped.
Any idea how what can be causing thing and how to fix it? Thanks in advance!
Some extra details, as requested by commenters:
Output of ruby -v:
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03
Output of gem -v:
1.8.6
Calling ruby script/console outputs a similar error (edited):
Loading development environment (Rails 2.3.4)
/var/www/sites/example.com/releases/20110726061310/config/environment.rb:12:NameError: uninitialized constant Gem
/usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:254:in `require': no such file to load -- console_app (LoadError)
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:254:in `load_modules'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:252:in `each'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb/init.rb:21:in `setup'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/irb.rb:54:in `start'
from /usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/irb:17
I'm trying to call Ferret Server to allow Passenger to connect to it, with the command:
ruby --debug script/ferret_server -e production start
Outputs the following error:
Exception `NameError' at ./script/../vendor/plugins/acts_as_ferret/lib/../../../../config/environment.rb:12 - uninitialized constant Gem
uninitialized constant Gem
Alternatively, calling bundle exec ruby --debug script/ferret_server -e production start outputs the following error:
superclass mismatch for class GemDependency
Please note that I added the following right above the Rails::Initializer.run do |config| line in config/environment.rb:
require 'thread'
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
def requirement
r = super
(r == Gem::Requirement.default) ? nil : r
end
end
end
end
require File.join(File.dirname(__FILE__), 'boot')
Remove the lines mentioned above gives uninitialized constant Rails errors instead.
Try putting:
require 'rubygems'
Just after require 'thread'

Resources