cannot load such file -- aws-sdk-elastictranscoder> - ruby-on-rails

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

Related

Gem works in IRB but not Rails console

I am trying to use the Hubspot API Ruby gem located here https://github.com/HubSpot/hubspot-api-ruby#installation, but I am having issues with Ruby on Rails.
For all of my other gems, I can just simply add the gem in the Gemfile and it works within the application, but not this case and I cannot figure out why.
For example, here's what I have in my Gemfile:
# HubSpot API Client
gem 'hubspot-api-client'
I have ran bundle install and it installed successfully, but I still can't use that gem. If I load the gem via the irb console, then it works just fine.
Here's what I mean:
Using IRB
root#8af3866a29c8:/myapp# irb
irb(main):001:0> require 'hubspot-api-client'
=> true
irb(main):002:0> Hubspot
=> Hubspot
Using Rails Console
root#8af3866a29c8:/myapp# rails c
Running via Spring preloader in process 6589
Loading development environment (Rails 5.2.4)
irb(main):001:0> require 'hubspot-api-client'
Traceback (most recent call last):
1: from (irb):1
LoadError (cannot load such file -- hubspot-api-client)
irb(main):001:0> Hubspot
Traceback (most recent call last):
1: from (irb):1
NameError (uninitialized constant Hubspot)
irb(main):002:0>
Why does this happen and how do I fix this?
You have to include gem 'hubspot-api-client' in your Gemfile.
Rails only load the gems which are specified in your Gemfile.

Bundled gem appears in Gemfile.lock but not available in app

I'm looking to use a couple of new gems in my project, 'ruby-fftw3' and 'aubio'. The project has been happily working away and being extended but now every time I try and add a new gem it's unavailable when I try and call it.
The gems are listed in the Gemfile:
gem 'aubio'
gem 'ruby-fftw3'
When I run bundle install they are listed:
Using aubio 0.3.1
...
Using ruby-fftw3 1.0.2
Gemfile.lock also contains both items.
However, when I open rails c and try to use the gem they're unavailable:
irb(main):001:0> require 'ruby-fftw3'
Traceback (most recent call last):
1: from (irb):1
LoadError (cannot load such file -- ruby-fftw3)
irb(main):002:0> Aubio
Traceback (most recent call last):
1: from (irb):2
NameError (uninitialized constant Aubio)
It also appears that Bundler.require(:default).collect(&:name) does not contain either gem!
I've gone through the Gemfile and can't see any formatting errors and if there were any I don't think bundle install would create a lock file which included them.

Ruby require - cannot load such file - my own gem

I've pushed gem into rubygems. I can install it, but I can't require it.
irb(main):032:0> require 'jsql'
Traceback (most recent call last):
4: from C:/Ruby25-x64/bin/irb.cmd:19:in `<main>'
3: from (irb):32
2: from C:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:122:in `require'
1: from C:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:122:in `require'
LoadError (cannot load such file -- jsql)
I've had this problem once, with mechanize gem.
It seems you've create a gem called jsql which is listed on https://rubygems.org/gems/jsql.
So in orer to use it, you need to install it, either with gem install jsql or add it to the Gemfile of you project, along with other dependencies, and run bundle install
Only after this procedures, your gem will be available for use.
This generally occurs when the gem isn't installed for the ruby version you're using.
It happened to me with the irb gem, so I ran
RBENV_VERSION=2.6.3 gem install irb
I found that helpful note here. But the same could apply for any gem, just check the ruby version with ruby --version and try the above code (replacing irb with whatever gem you want to install)

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.

LoadError on require yajl

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)

Resources