Resque cannot load module - no such file - ruby-on-rails

I am doing resque in Rails. In the Rails project, I have a file name setup.rb and helper.rb in the same directory. In setup.rb I have
require './helper'
When I tried to run bundle exec rake resque:work QUEUE="*" or rake resque:work QUEUE="*" I got error. The error is:
No such file to load -- ./helper
When I tried to rails console, Dir.chdir to that directory and type in require './helper' it return true, which means it works fine. I cannot explain why the setup.rb cannot require './helper'.

try using Rails.root for the file path and make it absolute instead of relative

Related

rake aborted! cannot load such file Ruby on Rails

I am trying to run a ruby file that updates the database using the rake task . But overtime I run the code, I get an error saying :
rake aborted!
cannot load such file -- app/services/insert_data
The ruby file 'insert_data' is located under the app directory in a folder named 'services'
Here is the rake task I created to run it:
require 'app/services/insert_data'
namespace :record_generate do
task :test do
ruby "app/services/insert_data"
end
end
Please help in removing this error.
To be able to use Rails environment within a rake task you need to declare that:
namespace :record_generate do
task :test => :environment do |_, args|
ruby "app/services/insert_data"
end
end
I think you should try placing your app/services/insert_data inside the script directory. I'm assuming that your ruby file is not a rails model with logic. I would try this.
Get your file and place it in the /script/ directory.
Place these line of code at the top of your file
#! /usr/bin/env ruby
require_relative "../config/environment"
Now on your command line you can do execute this:
rails runner name_of_your_file
That is one way of doing it. If you specifically need to use a rake task I can try posting an answer for that too.
Inside your task :test block try -
Rake.application.rake_require "#{Rails.root}/app/services/insert_data"

Rspec command returns '`require': cannot load such file -- spec_helper' when rake spec does not

I am humming along running my unit tests. For each file, I write a test and then run rspec on it to make sure I've written things correctly. I'm using rvm, sourcing ruby v2.1.1. I successfully run the command ruby -S spec/controllers/current_spec.rb
At some point, I run rake spec for all tests
After this, when I run ruby -S spec/controllers/current_spec.rb again I get the following error:
ruby -S spec/controllers/current_spec.rb
/home/eggmatters/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext
/kernel_require.rb:55:in `require': cannot load such file -- spec_helper (LoadError)
from /home/eggmatters/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext
/kernel_require.rb:55:in `require'
from spec/controllers/current_spec.rb:1:in `<main>'
The top of my spec contains:
require 'spec_helper'
Which is throwing the error. spec_helper is where it is supposed to be: spec/spec_helper.rb
Also, when running rake spec, all it does is issue the spec commands for each individual file in the spec directory for example:
$ rake spec:controllers
/home/eggmatters/.rvm/rubies/ruby-2.1.1/bin/ruby -S rspec
./spec/controllers/some_controller_spec.rb
./spec/controllers/another_controller_spec.rb
./spec/controllers/this_controller_spec.rb
./spec/controllers/current_controller_spec.rb
I've verified that ruby -S does indeed point to /home/eggmatters/.rvm/rubies/ruby-2.1.1/bin/ruby -S (which ruby).
The Gemfile looks fine. Running bundle exec ruby -S ./spec/controllers/current_controller_spec.rb throws the same error.
I ran rails generate spec:install already as I started out issuing the command just fine. There were no changes to spec_helper between successful runs.
bundle install doesn't change anything.
What's going on? Why is rspec all of the sudden not finding spec_helper when it is where it needs to be? What did rake do to rspec to all of the sudden break it? Why does rake spec work and this one doesn't?

How to run a rake task by command line in rails

I have defined a rake task as follows in a file called file_locker_task.rake
namespace :myspace do
task :process => :environment do
FileLocker.lock_files
end
end
How do I execute this rake task from the command line?
I tried:
rake myspace:process and rake process but both are throwing an error like this:
rake aborted!
Don't know how to build task 'process'
Run rake -T -A from your Rails home directory to see all the tasks that rake knows about. Yours must be in that list for rake to run it.
By default, in a Rails app, rake looks in the lib/tasks directory and its subdirectories for your .rake files. Check that. (I suspect this is the problem.)
According to docs
Any ruby file (including other rakefiles) can be included with a standard Ruby require command.
-
Additional rake files (with the file extension “.rake”) may be placed in rakelib directory located at the top level of a project (i.e. the same directory that contains the main Rakefile). Also, rails projects may include additional rake files in the lib/tasks directory.

Asset rake tasks not available on Rails 3.1 app in production

When I run "bundle exec rake -T" in development, the assets:clear and assets:precompile tasks show up, but if I prefix that command with RAILS_ENV=production, or run it on a server where that variable is set, they don't. Has anyone run into this?
I'd removed rails/all from the application.rb and replaced it with the individual railties, excluding activerecord. Turns out you also need to require the sprockets railtie.

How to build task 'gems:install'

I am deploying my rails app to a linux server and i have some of the rake tasks missing inlcuding rake gems:install and rake db
I am running rails 2.3.4 from GEM.
Why is this?
How do I fix this? can I update somehow?
they are missing from rake -T list
rake apache2 # Build Apache 2 module
rake clean # Remove compiled files
rake clobber # Remove all generated files
rake default # Build everything
rake doc # Generate all documentation
rake doxygen # Generate Doxygen C++ API documentation if ...
rake doxygen:clobber # Remove generated Doxygen C++ API documenta...
rake doxygen:force # Force generation of Doxygen C++ API docume...
rake fakeroot # Create a fakeroot, useful for building nat...
rake nginx # Build Nginx helper server
rake package # Build all the packages
rake package:clean # Remove package products
rake package:debian # Create a Debian package
rake package:force # Force a rebuild of the package files
rake package:gem # Build the gem file passenger-2.2.4.gem
rake rdoc # Build the rdoc HTML Files
rake rdoc:clobber # Remove rdoc products
rake rdoc:force # Force a rebuild of the RDOC files
rake sloccount # Run 'sloccount' to see how much code Passe...
rake test # Run all unit tests and integration tests
rake test:cxx # Run unit tests for the Apache 2 and Nginx ...
rake test:integration # Run all integration tests
rake test:integration:apache2 # Run Apache 2 integration tests
rake test:integration:nginx # Run Nginx integration tests
rake test:oxt # Run unit tests for the OXT library
rake test:rcov # Run coverage tests for the Ruby libraries
rake test:restart # Run the 'restart' integration test infinit...
rake test:ruby # Run unit tests for the Ruby libraries
my rake file contains this:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
How do I add the gems and db rake tasks? and why are they missing?
What is the output of rake -T? This should list all avaiable tasks. In a RoR application, the Rakefile defines your tasks.
You can update gems using gem update.
Check your Capfile, if you are in fact running the gems:install from Capistrano. Apparently, the way to do this is to ensure you're in the right directory internally when running Capistrano.
namespace :gems do
desc "Install gems"
task :install, :roles => :app do
run "cd #{current_path} && #{sudo} rake RAILS_ENV=production gems:install"
end
end
You could also always specify the Rakefile to be sure using the -f [FILE] option in front of the rake command.
You could try updating your Rails install, or reinstalling rails altogether by passing the --force flag. Do you have any other projects for which this command works? Check the rake files from those projects. It looks like your rakefile is the same as mine though... Is this project originally based on an older version of rails? What Gem version are you running? You might need to do a gem update --system. All these are possibilities.
I suppose you could always recreate your project. Annoying but always seems to help worst case scenario.
At least that'll give you an idea of whether or not it's the project or something in some kind of dependencies issue.
If you are using a rails app, you also have rake tasks defined in lib/tasks/SOME_TASK.rake
if you define the SOME_TASK it will then show up when you run rake -T and be an available command.

Resources