Bundler cannot find `whenever` gem, when deploying using capistrano - ruby-on-rails

I am trying to deploy my app in a staging environment using Capistrano.
Running cap staging deploy results in error saying:
bundler: failed to load command: whenever (/home/ubuntu/builder/shared/bundle/ruby/2.7.0/bin/whenever)
DEBUG [52d26072] Gem::Exception: can't find executable whenever for gem whenever. whenever is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
I have already included whenever gem in the local Gemfile but still it is not able to find it:
Here's a part of my Gemfile:
gem 'capistrano',
gem 'capistrano-secrets-yml'
gem 'capistrano-rbenv'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'whenever', :require => false
I am not able to find what the problem is. Can you please help me?

I would try bundle exec cap staging deploy to make sure you are executing the command using your bundle. Additionally you may need to remove require => false because it does not include the library when you load your bundle.

Related

install gem in local machine

I am using pry gem for debugging my rails application. So I have
specified it in my Gemfile and using it. But I dont need to push the
Gemfile with pry gem specified. So everytime I need to revert it to
original Gemfile and push it to remote repo.
I was wondering is there any way where I can install pry gem in my
local machine and use it in my rails app globally so that I dont have
to specify that gem in Gemfile.??
I tried to do
gem install pry
But when I use binding.pry in my rails controller, it says
undefined method `pry' for #<Binding:0x0000000619398>
With bundler you can create groups according to your environments.
You can intall your gem only for the development group.
Put the line below in your gemfile.
gem 'pry', :group => :development

Error pushing to heroku - aborting my rake assets:precompile

Edit: I'm a new ruby on rails student.
Following my Git Push Heroku Master, I am running into issues with Heroku. Here is the latest and greatest, aborting the rake assets:precompile.
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Tasks: TOP => environment
(See full trace by running task with --trace)
Precompiling assets failed, enabling runtime asset compilation
Injecting rails31_enable_runtime_asset_compilation
Please see this article for troubleshooting help:
http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
Included below are the contents of my Gemfile:
gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.1'
gem 'pg'
group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'guard-spork'
gem 'spork'
gem 'annotate'
gem 'database_cleaner'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
end
platforms :jruby do
gem 'trinidad'
gem 'jruby-openssl'
end
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
gem 'RedCloth', '~> 4.2.9', :require => 'redcloth'
gem 'ruby-openid', :require => 'openid'
gem 'rack-openid', :require => 'rack/openid'
gem 'aaronh-chronic', :require => 'chronic' # Fixes for 1.9.2
gem 'coderay'
gem 'lesstile'
gem 'formtastic'
gem 'will_paginate', '~> 3.0.2'
gem 'exception_notification', '~> 2.5.2'
gem 'open_id_authentication'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :test do
gem 'database_cleaner'
gem 'cucumber-rails', :require => false
gem 'cucumber-websteps', :require => false
gem 'factory_girl'
gem 'rspec'
gem 'nokogiri', '~> 1.5.0'
gem 'webrat'
end
What might be the issue?
Update: I ran the rake command with --trace, and it had alerted me with a failure because the production database did not exist. I created the database, and ran --trace again, and this is what I'm currently being thrown:
Command failed with status (1): [/usr/local/Cellar/ruby/1.9.3-p286/bin/ruby...]
See the Rails 3.1+ Asset Pipeline on Heroku Cedar article. This exact scenario is covered in the Troubleshooting section.
In short, your Heroku application has a strong separation between building (including asset compilation) and running (where your application becomes available). This is consistent with the 12-factor app principles, but it means that your application cannot access any configured resources during the build phase -- including the database -- meaning ActiveRecord is unavailable during asset precompilation.
You can tell Rails not to bootstrap your application during asset compilation in config/application.rb:
config.assets.initialize_on_precompile = false
The troubleshooting section also recommends:
If rake assets:precompile is still not working, you can debug this locally by configuring a nonexistent database in your local config/database.yml and attempting to run rake assets:precompile. Ideally you should be able to run this command without connecting to the database.
I struggled with exactly the same problem, for hours tonight. After adding
config.assets.initialize_on_precompile = false
to application.rb, remember to do a
git commit
right afterwards. I forgot to do this, and Heroku had no idea I'd changed application.rb. They don't have this extra line on their troubleshooting page.
For Rails 4
Enable Heroku Labs feature to fix this problem
heroku labs:enable user-env-compile
I had this issue with Rails 4 and none of the other suggestions helped. I finally figured it out and it was due to the Rollify gem trying to connect to the database. That has been fixed in the Rollify gem, however, you may need to grab the latest source code to get the fix. I just change my gem import for Rollify to:
gem 'rolify', :git => 'git://github.com/EppO/rolify.git'
That seemed to fix the problem and I haven't had to do any of the other suggestions.
Don't forget to bundle install and commit the change to git.
Also, if that doesn't fix your problem either, you might want to start looking closely at the gems you're using and make sure none of them attempt to connect to the database.

Bundler error on deployment

I'm currently using guard i.e. guard-coffeescript gem to compile my javascript (and in the future I'll probably add some more guard tasks) on my OSX dev system. I added the rb-fsevent gem to my Gemspec, now I saw that in a lot of Gemspecs it is added with an if statement like this:
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
Trying to deploy to my staging/production environment, which is running under Linux, the script executed on the server uses the bundle install --deployment results in following exception:
# bundle install --deployment
You have modified your Gemfile in development but did not check
the resulting snapshot (Gemfile.lock) into version control
You have deleted from the Gemfile:
* rb-fsevent
Is there a way around this problem or do I just have to remove the if so that I can deploy to my system and in turn installing a gem that is useless on a non OSX platform?
--
edit: I run bundle install before deploying to my staging environment and run bundle check after the first time it failed. I got it running after removing the if statement..
I had a similar problem. If you're using capistrano you can set the following option:
set :bundle_without, [:darwin, :development, :test]
Then wrap your gem 'rb-fsevent' line in a group called darwin. Something like this should work nicely:
group :test, :darwin do
gem 'rb-fsevent'
end
This makes bundler do this on the server:
bundle --without darwin development test
Which means that it ignores those groups in the Gemfile.lock. What you were doing would make you OS X machine and your server come up with different resulting lock files. Which is why it was complaining.
I had the exact same issue and Luke's solution fixed it for me, however, only after I removed the :require => false if RUBY_PLATFORM =~ /darwin/i string that is commonly used.
As described in
https://github.com/guard/guard
the solution is simply
group :development do
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
end

Launching RoR server for an existing app gives error

I just made my first setup of RoR, and creating a new application works fine. But when I want to run the rails server I get the following error:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.3/lib/delayed/yaml_ext.rb:30:in 'remove_method': method 'to_yaml' not defined in Class (NameError)
I ran the "bundle install" in the app directory and installed all the necessary files (with some problems however, but I excluded the gems with problems in the gemfile) and the last bundle install said that I have successfully installed all the needed packs.
I'm lost and I can't find a similar error on the internet. Can you help me?
EDIT: I forgot to mention that I'm not having a problem with a new application. It's running an existing one (that I didn't build, but works fine for others) that the error is related to. Here's the gemfile for that app:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'mysql'
gem "haml", ">= 3.0.0"
gem "haml-rails"
gem 'simple_form'
gem 'delayed_job'
#gem 'auto_crawlers'
gem 'will_paginate', '~> 3.0.beta'
group :test do
gem 'factory_girl_rails'
gem 'mocha'
end
group :development do
#gem "nifty-generators", "0.4.3", :git => "git://github.com/JonasNielsen/nifty-generators.git"
gem 'fastercsv'
end
gem "mocha", :group => :test
Do you think the error is because I left out the two gems with "#" ? Those were causing problems at first, and I don't think I need them to test some minor changes in the app (some views that I have to modify)
The issue is being described, and supposedly fixed here: https://github.com/collectiveidea/delayed_job/issuesearch?state=open&q=yaml#issue/194
Try this from the command line: irb -rubygems -r delayed_job and then from your bundled directory bundle-exec irb -rubygems -r delayed_job which will show if there is a difference between your system gems and your bundled setup - you might see an error in one or both attempts to run IRB.
If there is an error using bundle-exec but not with your system gems then it's a bundler issue. If not, are you sure the app is designed to function under Ruby 1.9? It looks like to_yaml isn't available at the point DJ is required, which implies it probably needs a require "yaml" somewhere.

Pushing rails app to heroku not working

I'm trying to use git push heroku master to upload my rails 3 app to heroku, but I keep getting the following error:
-----> Heroku receiving push
-----> Removing .DS_Store files
-----> Rails app detected
! Heroku Bamboo does not include any Rails gems by default.
! You'll need to declare it in either .gems or Gemfile.
! See http://docs.heroku.com/gems for details on specifying gems.
! Heroku push rejected, no Rails gem specified.
error: hooks/pre-receive exited with error code 1
I've tried deleting the on the heroku website and starting again, i've also tried wiping out my git repo and doing init again, and I keep getting the same error. My Gemfile is as follows:
source :rubygems
gem 'rails', '3.0.3'
gem 'recaptcha', :require => 'recaptcha/rails'
gem 'devise', '1.1.3'
gem 'acts-as-taggable-on'
gem 'ruby-debug'
# for sass
gem 'haml'
gem 'mocha'
gem 'ruby-pg'
I've run bundle package to package teh gems into vendor cache, but it doesn't seem to change the result.
I upgraded this app from rails 2.3, so i'm wondering if that has anything to do with it?
This is the answer I got from Heroku:
Hi,
The problem seems to be that your Gemfile is called GemFile. While that'll work on some platforms like the Mac, that won't work on a strictly case-sensitive filesystem, such as ours.
In order to rename the file in a case-retaining, case-insensitive file system like HFS or NTFS, you'll need to do it in two steps:
git mv GemFile Gemfile.temp
git mv Gemfile.temp Gemfile
Try adding these to your Gemfile
gem 'pg' # Heroku's DB runs on postgresql
gem 'heroku'

Resources