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.
Related
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
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.
I am trying to run a project downloaded from internet, it is ruby on rails, I am getting the following error
Traceback (most recent call last):
4: from bin/rails:3:in `<main>'
3: from bin/rails:3:in `load'
2: from C:/Users/Amira/canvas/bin/spring:10:in `<top (required)>'
1: from C:/Users/Amira/canvas/bin/spring:10:in `read'
C:/Users/Amira/canvas/bin/spring:10:in `read': No such file or directory # rb_sysopen - C:/Users/Amira/canvas/Gemfile.lock (Errno::ENOENT)
The code written in the file is as following
#!/usr/bin/env ruby
# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.
unless defined?(Spring)
require 'rubygems'
require 'bundler'
if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m))
Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) }
gem 'spring', match[1]
require 'spring/binstub'
end
end
It is an opensource project and I am new on rails
can anyone please help me ?
EDIT
Gemfile content
# What have they done to the Gemfile???
#
# Relax. Breathe deep. All the gems are still there; they're just loaded in various files in Gemfile.d/
# This allows us to require gems locally that we might not want to commit to our public repo. We can maintain
# a customized list of gems for development and debuggery, without affecting our ability to merge with canvas-lms
#
# NOTE: this file has to use 1.8.7 hash syntax to not raise a parser exception on 1.8.7
#
# NOTE: some files in Gemfile.d/ will have certain required gems indented. While this may seem arbitrary,
# it actually has semantic significance. An indented gem required in Gemfile is a gem that is NOT
# directly used by Canvas, but required by a gem that is used by Canvas. We lock into specific versions of
# these gems to prevent regression, and the indentation serves to alert us to the relationship between the gem and canvas-lms
source 'https://rubygems.org/'
Dir[File.join(File.dirname(__FILE__), 'gems/plugins/*/Gemfile.d/_before.rb')].each do |file|
eval(File.read(file), nil, file)
end
require File.expand_path("../config/canvas_rails_switcher", __FILE__)
Dir.glob(File.join(File.dirname(__FILE__), 'Gemfile.d', '*.rb')).sort.each do |file|
eval(File.read(file), nil, file)
end
The Gemfile usually specifies the dependencies (other code the application needs). The project you look into seems to use a slightly more complex setup.
Normally it works roughly like this:
Once the dependencies are installed via bundler (the command bundle or the more explicit bundle install), a Gemfile.lock is placed next to it to list the actually used versions of the installed dependencies.
Two takeaways:
use bundle (the gem is called bundler) to install dependencies.
read the README of the project carefully. If it does not have instructions on installation, create an issue if the projects has a method to do so. If you are hypernice or normal and the project is open and healthy, create a Pull Request for the README in which you describe how you managed to install the app.
Edit this might have sounded a bit arrogant, and I did not peek into the details. I assume you followed https://github.com/instructure/canvas-lms/wiki/Quick-Start . The canvas-lms project uses a setup slightly more complex than your typical Rails application. I believe you should ask specifically for help with canvas installation (edit your question).
Any rails command doesn't work for me. I have several versions of ruby installed through rvm. I tried installing rails with all the versions, they do install successfully but with all of them I face the following error whenever I run any rails command in my project directory:
~ rails new blog
Traceback (most recent call last):
1: from bin/rails:3:in `<main>'
bin/rails:3:in `require_relative': cannot load such file -- /Users/Am33d/Documents/config/boot (LoadError)
I tried looking up for the error but didn't find any solutions.
What can be done to fix this? I am using macOS Mojave (10.14.6)
This error would indicate that you do not have a boot.rb file in your config directory for some reason. When running rails commands -- regardless of if you run them as bin/rails [command] or bundle exec rails [command], runs the bin/rails file. This file typically has a line require_relative '../config/boot. The boilerplate bin/rails file in a new Rails 6 app is:
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
To simply fix this you can create a blank file by running touch config/boot.rb from the root directory of your application and that would itself suppress the error. Having said that, you'd be better off creating a config/boot.rb file that contains useful information. The boilerplate config/boot.rb file is this
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
Without this file you are not necessarily appropriately loading the gems from your gemfile or caching operations with bootsnap.
When I ran into this problem, I also received the same error when trying to use rails -s.
If the same is happening for you, its because your version of ruby isn't compatible with your rails version.
After upgrading to the latest rails version the error stopped and everything worked well.
A little bit weird.
rails new blog should not need to find boot file, neither need bundler. Actually, you are trying to create a new project, so it is expected there is not Gemfile, boot, or bundler created for your project.
So I would advise you to find what rails command is being executed. Sometimes one rails executable created by bundler is taking precedence in the $PATH environment variable.
Ex: some incorrect bin/rails executable is on your $HOME directory.
i was trying to build an app using 'rails server' and this error was showing. You have to make sure that the rails version matches the ruby version and even if you do what an answer above said (create the config/boot.rb paste) doesnt work, than you have to change the version of rails to the stable. I'll let the link of this problem here, there's an issue closed in github for this problem https://github.com/rails/rails/pull/43951
to solve the problem you have to replace the gem rails line on the gemfile to this:
gem "rails", github: "rails/rails", branch: "7-0-stable"
Sorry about my english.
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)