Error: Rake Aborted. Uninitialized Constant Settings - ruby-on-rails

Newbie here trying to create a development environment for a project. I've installed MySQL and Ruby on Rails on my device already. However, I'm running into the below error message when trying to run the 3 commands below after "bundle install" runs successfully. Any ideas?
bundle exec rake db:setup RAILS_ENV="development"
bundle exec rake db:migrate RAILS_ENV="development"
bundle exec rake db:seed RAILS_ENV=“development"
error message is as follows:
wcai-projects already exists
rake aborted!
uninitialized constant Settings
EDIT-here's the console log:
$ bundle exec rake db:setup RAILS_ENV=development
/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-3.2.12/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
wcai-projects already exists
rake aborted!
uninitialized constant Settings
/wcai-web/config/initializers/carrier_wave.rb:4:in `block in <top (required)>'
/wcai-web/config/initializers/carrier_wave.rb:1:in `<top (required)>'
/wcai-web/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => environment
(See full trace by running task with --trace)
EDIT-contents of config/initializers/carrier_wave.rb:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => Settings.aws_access_key, # required
:aws_secret_access_key => Settings.aws_secret_key # required
# :region => 'eu-west-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = Settings.aws_bucket # required
config.fog_public = false
config.fog_authenticated_url_expiration = 120
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
#config.asset_host = 'https://assets.example.com' # optional, defaults to nil
end

Update your Rails version in Gemfile to 4.2.4. Then type bundle update rails and try again.

Related

rake db:migrate rake aborted! NoMethodEr

When I try to run rake db:migrate I am getting following error:
DEPRECATION WARNING: The factory_girl gem is deprecated. Please upgrade to factory_bot. See https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md for further instructions. (called from <top (required)> at /var/www/html/sophy_web/config/application.rb:14)
/root/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-4.2.8/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::PDF
/root/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack-4.2.8/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of PDF was here
rake aborted!
NoMethodError: undefined method `>' for nil:NilClass
/var/www/html/application/config/initializers/rollbar.rb:2:in `<top (required)>'
/var/www/html/application/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
I am using ruby version 2.5.1 and rails 4.2.8.
Code of my rollbar.rb:
require 'rollbar/rails'
Rollbar.configure do |config|
config.access_token = '9234902384023843203fsd23'
# Here we'll disable in 'test':
if Rails.env.test?
config.enabled = false
end
end
Code of my environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!

Capistrano undefined local variable or method and Argument Error

Trying to run cap deploy:check I get this error:
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host #<SSHKit::Host:0x007fc04888dcf8>: undefined local variable or method `rubber_env' for #<SSHKit::Backend::Netssh:0x007fc04888d050>
NameError: undefined local variable or method `rubber_env' for #<SSHKit::Backend::Netssh:0x007fc04888d050>
(See full trace by running task with --trace)
Capfile
gemfile = File.expand_path(File.join(__FILE__, '..', 'Gemfile'))
if File.exist?(gemfile) && ENV['BUNDLE_GEMFILE'].nil?
puts "Respawning with 'bundle exec'"
exec("bundle", "exec", "cap", *ARGV)
end
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
env = ENV['RUBBER_ENV'] ||= (ENV['RAILS_ENV'] || 'production')
root = File.dirname(__FILE__)
# this tries first as a rails plugin then as a gem
$:.unshift "#{root}/vendor/plugins/rubber/lib/"
require 'rubber'
Rubber::initialize(root, env)
require 'capistrano'
require 'capistrano-passenger'
require 'bundler'
require 'rails'
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy.rb'
I think I fixed the problem by putting set :rubber_env in deploy.rb, but now I get this error
cap aborted!
ArgumentError: wrong number of arguments (1 for 2)
/Users/user1/app1/Capfile:24:in `load'
/Users/user1/app1/Capfile:24:in `<top (required)>'

capistrano 3 + rvm1-capistrano3 rails 4.1 secrets.yml environmental variables issue

I have been deploying rails 4.1 application with capistrano 3. it has been working fine. but
when i tried to do rake tasks (uncommenting require 'capistrano/rails/assets'). i get this error
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: Nothing written
rake stderr: config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
rake aborted!
ArgumentError: Missing required arguments: google_storage_access_key_id, google_storage_secret_access_key
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:237:in `validate_options'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:261:in `handle_settings'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:98:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/storage.rb:26:in `new'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:8:in `block in <top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
/home/deploy/yelo/releases/20140910131617/config/initializers/carrierwave.rb:5:in `<top (required)>'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
/home/deploy/yelo/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
the config.eager_load is set to true. the thing with google_storage_access_key_id the keys are initialized inside a initializer with values config.secrets.yml
require 'fog'
require 'rails'
require 'carrierwave'
CarrierWave.configure do |config|
config.root = Rails.root.join('tmp')
config.cache_dir = 'carrierwave'
config.fog_credentials = {
:provider => 'Google',
:google_storage_access_key_id => Rails.application.secrets.storage_access_key,
:google_storage_secret_access_key => Rails.application.secrets.storage_access_secret
}
config.fog_directory = 'yelostore'
end
config.secrets.yml
storage_access_key: <%= ENV['STORAGE_ACCESS_KEY']%>
storage_access_secret: <%= ENV['STORAGE_ACCESS_SECRET']%>
i stored my environmental variables in /etc/profile.
there issues arise only if i do some rake or execute tasks.
if i removed the initializer file i get another error
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = '6b88a299ed1361b5c0275e.....'
this is essentiall because of secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> not getting loaded at that point.
Finally i can run all tasks i go to the root path. only while doing it through capistarno these errors arise. as capistarno not getting the config.scecrets env variables which is stored in /etc/profile
capistrano seems like to look into environmental variables from /etc/environment rather than shell so bashrc or profile didnt't work.
The config.eager_load issue was solved after i upgraded to capistrano 3.0rc to 3.2
The Error has nothing to do with the secret_key_base.
In the file config/initializers/devise.rb add the config.secret_key='6b88...' within the setup block:
Devise.setup do |config|
config.secret_key = '6b88a299ed1361b5c0275e...'
...
end

Enhance assets:precompile on Heroku to add non fingerptinted filenames

In a Rails 4 app, I want precompiled assets to have copies of some assets to be available with a non fingerprinted filename. The app is deployed on Heroku.
I have the following rake task in place:
namespace :app do
task :nonfingerprint_assets => :environment do
manifests = Rails.application.config.assets[:precompile]
manifests = manifests.slice(1, manifests.length)
assets = Dir.glob(File.join(Rails.root, 'public/assets/**/*'))
regex = /(-{1}[a-z0-9]{32}*\.{1}){1}/
assets.each do |file|
next if File.directory?(file) || file !~ regex
source = file.split('/')
source.push(source.pop.gsub(regex, '.'))
non_digested = File.join(source)
if manifests.any? {|m|
if m.is_a? Regexp
m.match non_digested
else
m.ends_with?(non_digested)
end
}
puts "** copy source: #{file}"
puts "** copy destination: #{non_digested}"
FileUtils.cp(file, non_digested)
end
end
end
end
Rake::Task['assets:precompile'].enhance do
puts "Invoke nonfingerprint_assets"
Rake::Task['app:nonfingerprint_assets'].invoke
end
This rake task is working fine on my local machine even in production environment. It creates a file in public/assets/application.js which is the copy of the same file with a digest in its name.
When I deploy this code to heroku I get the following error message which I don't understand:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_
locales = false to avoid this message.
Invoke nonfingerprint_assets
** copy source: /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application-51d1660b66655782ab137ee98c789fdd.js
** copy destination: /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application.js
rake aborted!
No such file or directory - /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application.js
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:26:in `block (3 levels) in <top (required)>'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:9:in `each'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:9:in `block (2 levels) in <top (required)>'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:45:in `block in <top (required)>'
Tasks: TOP => app:nonfingerprint_assets
(See full trace by running task with --trace)
Please help me to understand what's going on.

Rake task doesn't work in production

I have this rake task in a Rails 3.2.11 application in lib/rake/searches.rb:
namespace :searches do
desc "Start background searches"
task :start => :environment do
Rails.logger.info "Starting searches..."
Campaign.all.each do |c|
next unless c.recurring?
Rails.logger.info "Starting searches for campaign '#{c.name}'"
SearchWorker.enqueue(:campaign_id => c.id, :clear => true)
end
end
end
When I run it locally everything goes well. When I run it in production it errors out:
$ bundle exec rake searches:start
rake aborted!
uninitialized constant SearchWorker
/var/apps/web/lib/tasks/searches.rake:9:in `block (3 levels) in <top (required)>'
/var/apps/web/lib/tasks/searches.rake:5:in `block (2 levels) in <top (required)>'
Tasks: TOP => searches:start
(See full trace by running task with --trace)
When I jump into a console session, I can see that the class is correctly auto loaded:
$ bundle exec rails console
Loading production environment (Rails 3.2.11)
irb(main):001:0> SearchWorker
=> SearchWorker
This workers live in app/workers and they are added to the autoload_paths config setting in application.rb:
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(
#{config.root}/custom_scripts
#{config.root}/app/workers
#{config.root}/app/models/filters
)
So I have no clue why the error only occurs in production, and when running from a rake task.
Any ideas?
It seems you have created the rake file with .rb extension
lib/rake/searches.rb
can you try changing it to
lib/rake/searches.rake
That should work
This is due to the production environment in Rails 3.2 not being fully loaded, after the :environment task is complete.
If you explicitly require SearchWorker ie.
require 'app/workers/search_worker'
Within the beginning of the task block, it'll work.
(Why auto-loads isn't doing this for you, I don't know)

Resources