NoMethodError in Solidus when using external storage service - ruby-on-rails

I have a vanilla Solidus installation (ruby 3.0 | rails 6.1.5)
I'm using the edge guide to test a deployment on Heroku. I get the following error on my local machine if I configure active storage to use :amazon in my storage.yml file.
The remote deployment also results in an error. Running heroku logs --tail gives the following error in my Terminal:
from /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2022-03-24T21:23:47.656577+00:00 app[web.1]: from bin/rails:5:in `<main>'
2022-03-24T21:23:47.825835+00:00 heroku[web.1]: Process exited with status 1
2022-03-24T21:23:47.876809+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-24T21:23:47.885875+00:00 heroku[web.1]: State changed from crashed to starting
2022-03-24T21:23:54.753814+00:00 heroku[web.1]: Starting process with command `bin/rails server -p ${PORT:-5000} -e production`
2022-03-24T21:23:59.021982+00:00 app[web.1]: => Booting Puma
2022-03-24T21:23:59.022013+00:00 app[web.1]: => Rails 6.1.5 application starting in production
2022-03-24T21:23:59.022013+00:00 app[web.1]: => Run `bin/rails server --help` for more startup options
2022-03-24T21:24:00.921589+00:00 app[web.1]: Exiting
2022-03-24T21:24:00.922353+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activestorage-6.1.5/lib/active_storage/service/configurator.rb:17:in `build': undefined method `fetch' for nil:NilClass (NoMethodError)
2022-03-24T21:24:00.922355+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.0.0/gems/activestorage-6.1.5/lib/active_storage/service/registry.rb:13:in `block in fetch'
There are no errors if I configure active storage to use the local disk. Appreciate any assistance or insight.
Update:
Storage.ymltest:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
amazon:
service:S3
access_key_id: ""
secret_access_key:
region:
bucket:
Config/environment/production.rb
require "active_support/core_ext/integer/time"
Rails.application.configure do
config.cache_classes = true
config.active_storage.service = :amazon
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.compile = false
config.log_level = :info
config.log_tags = [ :request_id ]
config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.active_support.disallowed_deprecation = :log
config.active_support.disallowed_deprecation_warnings = []
config.log_formatter = ::Logger::Formatter.new
ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter=config.log_formatter
config.logger=ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false

Related

NoMethodError: undefined method `[]' for nil:NilClass when deploying on Heroku

this problem happens when trying to deploy on heroku, I figured it could be the master.key, I redid the project from scratch and the same error occurred. I'm a JS dev, and I'm studying hard to learn RoR.
thanks
I minimize the code error
rails aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/app/config/environments/production.rb:124:in `block in <main>'
...
`perform'
/app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.5/lib/rails/command.rb:50:in `invoke'
/app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.5/lib/rails/commands.rb:18:in `<main>'
/app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)
I refactor all. try a new repository, master.key new .
this is my production.rb
require 'active_support/core_ext/integer/time'
# rubocop: disable Metrics/BlockLength
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.active_storage.service = :local
config.log_level = :info
# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Log disallowed deprecations.
config.active_support.disallowed_deprecation = :log
# Tell Active Support which deprecation messages to disallow.
config.active_support.disallowed_deprecation_warnings = []
config.log_formatter = ::Logger::Formatter.new
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false
# Email
config.action_mailer.default_url_options = {
host: 'https://max-api-on-rails.herokuapp.com/'
}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain:'gmail.com',
user_name: Rails.application.credentials.zoho[:user_name],
password: Rails.application.credentials.zoho[:password],
authentication: 'login',
ssl: true,
tls: true,
enable_starttls_auto: true
}
end
Error is email smtp configuration. i using zoho, but my credentials is gmail.

Variable nill / undefined method , when deploying on heroku

i ask the question yesterday, but omitted some infos, im sorry
this problem happens when trying to deploy on heroku, I figured it could be the master.key, I redid the project from scratch and the same error occurred. I'm a JS dev, and I'm studying hard to learn RoR. thanks I minimize the code error
rails aborted!
NoMethodError: undefined method `[]' for nil:NilClass
/app/config/environments/production.rb:124:in `block in <main>'
...
`perform'
/app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.5/lib/rails/command.rb:50:in `invoke'
/app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.5/lib/rails/commands.rb:18:in `<main>'
/app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)
I refactor all. try a new repository, master.key new .
this is my production.rb
require 'active_support/core_ext/integer/time'
# rubocop: disable Metrics/BlockLength
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.active_storage.service = :local
config.log_level = :info
# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Log disallowed deprecations.
config.active_support.disallowed_deprecation = :log
# Tell Active Support which deprecation messages to disallow.
config.active_support.disallowed_deprecation_warnings = []
config.log_formatter = ::Logger::Formatter.new
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false
# Email
config.action_mailer.default_url_options = {
host: 'https://max-api-on-rails.herokuapp.com/'
}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain:'gmail.com',
user_name: Rails.application.credentials.zoho[:user_name],
password: Rails.application.credentials.zoho[:password],
authentication: 'login',
ssl: true,
tls: true,
enable_starttls_auto: true
}
end
I did deploy, and expected success. I learning rails, i dev Js/front end

Setting up database for the first time in ruby on rails

I am very much fresh in using Ruby on rails. I have cloned a git repo and trying to set up a PostgreSQL database in my local machine(Win 10).
Ruby version- 2.4.10
Rails - 5.2.0
I am using the below command
rake db:setup RAILS_ENV=development
Error Output -
rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass
D:/ruby/reserves/config/environments/development.rb:41:in `block in <top (required)>'
D:/ruby/reserves/config/environments/development.rb:1:in `<top (required)>'
D:/ruby/reserves/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create => db:load_config => environment
(See full trace by running task with --trace)
In database.yml file there are three environments has been declared - Development/Production/test
development:
<<: *default
database: reserves-dev
username:****
password:****
host: localhost
/config/environments/development.rb:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Email
config.action_mailer.perform_caching = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.smtp_settings = {
address: Rails.application.credentials[Rails.env.to_sym][:mailer][:address],
port: Rails.application.credentials[Rails.env.to_sym][:mailer][:port],
user_name: Rails.application.credentials[Rails.env.to_sym][:mailer][:username],
password: Rails.application.credentials[Rails.env.to_sym][:mailer][:password],
domain: Rails.application.credentials[Rails.env.to_sym][:mailer][:domain],
authentication: :plain
}
# NOTE: For email need to have authentication :login (instead of :plain) and
# the tls: true param, otherwise the server times out on password reset request.
Rails.application.config.middleware.use ExceptionNotification::Rack,
:ignore_crawlers => %w{Googlebot bingbot},
:ignore_exceptions => ['ActionController::InvalidCrossOriginRequest'] + ExceptionNotifier.ignored_exceptions,
:email => {
:email_prefix => "[ERROR] ",
:sender_address => %{"Arc Reserves" <noreply#*****.com>},
:exception_recipients => %w{info#****.com}
}
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
How can I set the environment variable to development for setting the database in my local.
Any help is highly appreciated.
Thank you in advance.
Most likely this is because of the lines like:
Rails.application.credentials[Rails.env.to_sym][:mailer][:address]
Could you change it to something like that?
Rails.application.credentials.dig(:mailer, :address)

Rails: Deploying a staging environment: Devise Secret Key was not set

Right now, our company has a working production version of our company hosted on cloud66. I went through and set all of our environment variables and got our manifest up to snuff. Right now, aside from our API keys, staging is an exact replica of production. Our production.rb file is the same as sour staging.rb file:
#staging.rb
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Mailer
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => "587",
:authentication => :plain,
:user_name => 'apikey',
:password => ENV['SENDGRID_API_KEY'],
:domain => ENV['BASE_DOMAIN'],
:enable_starttls_auto => true
}
# Mailer for Devise
config.action_mailer.default_url_options = { host: ENV['FULL_URL'] }
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "gathrly_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
I added the staging settings to our c66 manifest file, which again, is an exact copy of production:
# C66 manifest file
production:
postgresql:
configuration:
version: 9.6.1
postgis: false
staging:
postgresql:
configuration:
version: 9.6.1
postgis: false
Deployment failed and the logs are pointing to Devise:
#C66 deployment logs
[52.36.55.118] /var/deploy/OurApp/web_head/releases/20170311214608/config/database.yml
[52.36.55.118] done
* sftp upload complete
* executing `deploy:db:create'
* executing "cd /var/deploy/OurApp/web_head/releases/20170311214608 && bundle exec rake RAILS_ENV=staging db:create"
[52.36.55.118] executing command
Database 'OurApp_staging' already exists
command finished in 2328ms
* executing `deploy:db:load_schema'
* executing "cd /var/deploy/OurApp/web_head/releases/20170311214608 && bundle exec rake RAILS_ENV=staging db:schema:load"
[52.36.55.118] executing command
rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = **REDACTED**
Please ensure you restarted your application after installing Devise or setting the key.
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/devise-4.2.0/lib/devise/rails/routes.rb:498:in `raise_no_secret_key'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/devise-4.2.0/lib/devise/rails/routes.rb:226:in `devise_for'
/var/deploy/OurApp/web_head/releases/20170311214608/config/routes.rb:5:in `block in '
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:389:in `instance_exec'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:389:in `eval_block'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:371:in `draw'
/var/deploy/OurApp/web_head/releases/20170311214608/config/routes.rb:1:in `'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in `each'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_r
eloader.rb:26:in `block in updater'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/file_update_checker.rb:77:in `execute'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:27:in `updater'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application/finisher.rb:119:in `block in '
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!'
/var/deploy/OurApp/web_head/releases/20170311214608/config/environment.rb:5:in `'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:328:in `require_environment!'
/var/deploy/OurApp/web_head/shared/bundle/ru
by/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:448:in `block in run_tasks_blocks'
/var/deploy/OurApp/web_head/shared/bundle/ruby/2.3.0/gems/rake-11.3.0/exe/rake:27:in `'
/usr/local/bin/bundle:22:in `load'
/usr/local/bin/bundle:22:in `'
Tasks: TOP => db:schema:load => environment
(See full trace by running task with --trace)
command finished in 2584ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/deploy/OurApp/web_head/releases/20170311214608; true"
[52.36.55.118] executing command
command finished in 286ms
failed: ". /var/.cloud66_env 2>/dev/null || true && unset BUNDLE_GEMFILE && sh -c 'cd /var/deploy/OurApp/web_head/releases/20170311214608 && bundle exec rake RAILS_ENV=**REDACTED** db:schema:load'" on 52.36.55.118
21:47:27 – Deployment failed: Failed to setup the deployment on the server during "cap deploy"
So, I'm looking in the devise.rb file and I see this commented out code:
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = 'somekey' # Real key removed for security.
I don't know much about this chunk of code. I would assume since everything is an exact replica of production that this should stay commented out for our staging environment as well. I don't know the implications of uncommenting out the config.secret_key and what that might do to our production environment.
Can someone explain why this works in production but is failing in staging which is identical in the rest of the settings?
I found the issue. I forgot to add in staging information to secrets.yml where the secret_key_base is set.

uninitialized constant Dalli (NameError) in staging but not production

So I get a uninitialized constant Dalli (NameError) when I push my ruby on rails app to my staging on heroku, but it works fine in production. my production.rb and staging.rb files are the exact same except for a mailer host value. Could someone help? Thanks!
production.rb:
Novulty::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rails's static asset server
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Compress CSS using yui-compressor gem
config.assets.css_compressor = :yui
# Compress JS using uglifier gem
config.assets.js_compressor = :uglifier
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = false
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w[ *.js *.css ]
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
# Use SMTP to send mail
config.action_mailer.delivery_method = :smtp
# Use Gmail to send smtp mail
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "novulty.com",
:user_name => ENV["GMAIL_USERNAME"],
:password => ENV["GMAIL_PASSWORD"],
:authentication => :plain,
:enable_starttls_auto => true
}
# Specify what domain to use for mailer URLs
config.action_mailer.default_url_options = {
host: "novulty.com"
}
# Specify how long an item should stay cached by setting the Cache-Control headers
config.static_cache_control = "public, max-age=2592000"
# Specify Dalli as the storage backends for Rails’ built-in Rack::Cache integration
config.action_dispatch.rack_cache = {
:metastore => Dalli::Client.new,
:entitystore => 'file:tmp/cache/rack/body',
:allow_reload => false
}
end
staging.rb:
Novulty::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rails's static asset server
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Compress CSS using yui-compressor gem
config.assets.css_compressor = :yui
# Compress JS using uglifier gem
config.assets.js_compressor = :uglifier
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = false
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w[ *.js *.css ]
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
# Use SMTP to send mail
config.action_mailer.delivery_method = :smtp
# Use Gmail to send smtp mail
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "novulty.com",
:user_name => ENV["GMAIL_USERNAME"],
:password => ENV["GMAIL_PASSWORD"],
:authentication => :plain,
:enable_starttls_auto => true
}
# Specify what domain to use for mailer URLs
config.action_mailer.default_url_options = {
host: "novultystaging.herokuapp.com"
}
# Specify how long an item should stay cached by setting the Cache-Control headers
config.static_cache_control = "public, max-age=2592000"
# Specify Dalli as the storage backends for Rails’ built-in Rack::Cache integration
config.action_dispatch.rack_cache = {
:metastore => Dalli::Client.new,
:entitystore => 'file:tmp/cache/rack/body',
:allow_reload => false
}
end
production.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Novulty
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# Use dalli cache store in production
config.cache_store = :dalli_store
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Add Font-Awesome support (add app/assets/font to the asset path)
config.assets.paths << Rails.root.join("app", "assets", "fonts")
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
end
end
Here is the output of heroku logs --tail --remote staging:
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/engine.rb:571:in `block in <class:Engine>'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
2012-11-08T02:04:59+00:00 app[web.1]: /app/config/environments/staging.rb:96:in `block in <top (required)>': uninitialized constant Dalli (NameError)
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:24:in `class_eval'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:24:in `configure'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/config/environments/staging.rb:1:in `<top (required)>'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/config/environment.rb:5:in `<top (required)>'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/config.ru:4:in `require'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/config.ru:4:in `block in <main>'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/config.ru:1:in `new'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/config.ru:1:in `<main>'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
2012-11-08T02:04:59+00:00 app[web.1]: from script/rails:6:in `require'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:55:in `block in <top (required)>'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands/server.rb:70:in `start'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands/server.rb:46:in `app'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
2012-11-08T02:04:59+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
2012-11-08T02:04:59+00:00 app[web.1]: from script/rails:6:in `<main>'
Feel free to check out my code at www.github.com/sambaek/novulty
Have a look at your Gemfile:
group :production do
gem 'dalli'
end
Bundler does not load Dalli in your staging environment.
Either move it out of the :production group, so it's available in all environments, or add it to the :staging environment too.

Resources