I'm trying to run a script, which has a line:
require 'headless'
There are several other gems that are working perfect in the same script, here's httpd error log:
:/usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:128:in `require'
:cannot load such file -- headless
What is wrong here? I can see that I'm missing something, under
/usr/local/rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/ there is no core_ext directory.
I'm just trying to move some scripts from an old server to a new server.
Put gem "headless" in your Gemfile and run bundle install
Related
I'm trying to extract a couple of tasks into a gem, but cannot get the code to load in my Capfile. The code is at: https://github.com/floydj/capistrano-mysql_tables.
In my Gemfile:
gem "capistrano-mysql_tables", github: "floydj/capistrano-mysql_tables"
In my Capfile:
require "capistrano/mysql_tables"
After bundle install, it seems to be good, but running cap -T results in:
(Backtrace restricted to imported tasks)
cap aborted!
LoadError: cannot load such file -- capistrano/mysql_tables
What is wrong with the code in the gem? I've looked at other Capistrano plugins and have tried to imitate them, but it always gives this error and I've run out of things to try. It appears to be some kind of path problem, maybe. Here's what I see with gem contents:
$ bundle exec gem contents capistrano-mysql_tables
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/Gemfile
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/Gemfile.lock
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/LICENSE.txt
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/README.md
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/Rakefile
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/bin/console
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/bin/setup
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/capistrano-mysql_tables.gemspec
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/lib/capistrano-mysql_tables.rb
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/lib/capistrano/mysql_tables.rb
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/lib/capistrano/mysql_tables/version.rb
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/lib/capistrano/tasks/mysql_tables.rake
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/test/capistrano/mysql_tables_test.rb
/Users/username/.gem/ruby/3.0.4/bundler/gems/capistrano-mysql_tables-d1b60186a06b/test/test_helper.rb
Update:
After fixing the mistake found by #Alex, it still didn't work. However, I decided to push the gem to RubyGems, and then install via Gemfile in the standard way:
gem "capistrano-mysql_tables"
And after the standard install command, it works fine. But why does it work now? I suppose it has something to do with paths, the contents now list the following:
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/Gemfile
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/Gemfile.lock
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/LICENSE.txt
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/README.md
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/Rakefile
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/bin/console
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/bin/setup
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/capistrano-mysql_tables.gemspec
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/lib/capistrano-mysql_tables.rb
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/lib/capistrano/mysql_tables.rb
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/lib/capistrano/mysql_tables/version.rb
/Users/username/.gem/ruby/3.0.4/gems/capistrano-mysql_tables-0.0.2/lib/capistrano/tasks/mysql_tables.rake
I'm glad I got it working, but would like to know why it failed before? Any ideas?
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 am trying to use Rspec for my test. When I run
$ rspec mytest_spec.rb
I get the following error due to the
/home/bastien/.merbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- rails_helper (LoadError)
I have tried many things and somehow if I run
rspec spec
or
bundle exec rspec
from the folder where my .rspec file is I do not get any error. I have created an app just to dry test this issue (I created a new rail app, added rspec in my Gemfile, run the bundle install command and the rspec:install command, generated a scaffold and run the tests. Could anyone explain to me why I get this issue and how I can get rid of it? Do I do something wrong when I try to run only one single spec? Thanks.
You are getting that error because you're trying to call your spec like this...
rspec mytest_spec.rb
You need to call it like this from your app's root folder , not inside the spec folder. So first get in the right folder
cd ~/
cd path_to_your_rails_app
Then call your spec
rspec spec/the_rest_of_the_path_to_your_spec/mytest_spec.rb
for instance
rspec spec/models/mytest_spec.rb
For others who find this:
I got this error, 'require': cannot load such file -- rails_helper (LoadError), when I had included the rspec-rails gem but hadn't run rails generate rspec:install which generates the spec/rails_helper.rb file. So if the other solution doesn't help you, make sure you've done that.
For those that the answers above didn't help:
You just need to add gem 'rexml' to your Gemfile.rb, run bundle install and try again.
I have a ruby script I wrote which generates data and loads it to MongoDB. I am now trying to call this load script from seed.rb of my Rails app (so I can run via rake db:seed)
I attempted to call it from rails using this code:
system( "ruby data_load/db_load.rb -a data_load/doc1.json" )
When that code executes, I get the following error. (Note it runs fine from the command line):
data_load/db_load.rb:15:in `require': cannot load such file -- mongo (LoadError)
from data_load/db_load.rb:15:in `<main>'
The top of db_load.rb looks like this:
# includes gems from gemfile
require 'rubygems'
require 'bundler/setup'
Bundler.setup
require 'mongo'
require_relative 'load_scripts/cmd_options'
require_relative 'load_scripts/build_index'
....
include Mongo
The script has it's own gemfile in the data_load directory.
My guess is ruby is running the script using the bundle for the rails application instead of the shell script.
Any suggestions on how I can execute this script?
I believe the problem is where Bundler is looking for the Gemfile. Since your script is being run in the parent directly it is finding the Gemfile for the main app.
Set the BUNDLE_GEMFILE before calling your script:
system "BUNDLE_GEMFILE=data_load/Gemfile ruby data_load/db_load.rb -a data_load/doc1.json"
I'm sorry but I think you can't do it, unless you run the script as a different process (like a shell command), doing it is easy:
`shell_command params`
Just use the correct path and params.
Otherwise, consider that a gemfile is "more or less" at its basic level, a bunch of require (or load) statements, so loading a different gemfile would overwrite the original one, creating a lot of issue with rails after that.
The subprocess command is a good idea, however you can only pass string as params, not in-memory objects.
In development I'm running guard with liveReload. To make it run I had to add this lines to config.ru file:
require 'rack-livereload'
use Rack::LiveReload
before the line run Habrablog::Application. Without these lines LiveReload doesn't work for me.
The gems guard-livereload and rack-livereload are in the develpment group of Gemfile.
But when i'm pushing to heroku server i've got a message:
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-
3.2.2/lib/active_support/dependencies.rb:251:in `require':
no such file to load -- rack-livereload (LoadError)
Obviously it's because of livereload, how to eliminate the livereload configuration from production?
I don't think you need to add anything to your config.ru file (that's just for Sinatra).
Neither of the gem install guides mention this for Rails, the rack-reload settings go in config/environments/development.rb
https://github.com/guard/guard-livereload/
https://github.com/johnbintz/rack-livereload/