Rails environment config: `method_missing': undefined method `action_mailer'
Asked Answered
N

4

13

Attempting to invoke a Rails console (bundle exec rails c) or Rails server (bundle exec rails s) causes the following exception to be thrown:

~/project/.bundle/gems/railties-4.2.6/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `action_mailer' for #<Rails::Application::Configuration:0x007fdbe46e7400> (NoMethodError)
    from ~/project/config/environments/development.rb:43:in `block in <top (required)>'
    from ~/project/.bundle/gems/railties-4.2.6/lib/rails/railtie.rb:210:in `instance_eval'
    from ~/project/.bundle/gems/railties-4.2.6/lib/rails/railtie.rb:210:in `configure'
    from ~/project/config/environments/development.rb:1:in `<top (required)>'
    from ~/project/.bundle/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
...

Am I missing something here or there any other gems that could be causing an incompatibility issue?

This is the offending line in config/environments/development.rb:

  # Save emails to files instead of delivering.
  config.action_mailer.delivery_method = :file

The following is the contents of my Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.2.6'
gem 'activemodel'
gem 'actionmailer'
gem 'sass-rails', '~> 5.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'rollbar'
gem 'meta-tags'
gem 'faraday'
gem 'oj'
gem 'dalli-elasticache'
gem 'config'

# Frontend
gem 'jquery-rails'
gem 'jquery-turbolinks'
gem 'bourbon'
gem 'turbolinks'
gem 'therubyracer'

# Deploy
gem 'capistrano'
gem 'capistrano-rbenv'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-passenger'
gem 'capistrano-rails-console'
gem 'capistrano-rails-log'

group :development, :test do
  gem 'spring'
  gem 'spring-commands-rspec'
  gem 'byebug'
end

group :test do
  gem 'rspec-rails'
  gem 'capybara'
  gem 'launchy'
  gem 'webmock'
  gem 'capybara-webkit'
  gem 'vcr'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'quiet_assets'
end
Nullification answered 10/5, 2016 at 16:4 Comment(6)
Was it working before or did it never worked?Eatton
It never worked. This is the first time I'm attempting to use and configure actionmailer.Nullification
try remaining actionmailer from your gemfile then bundle installEatton
That made no difference, even after reinstalling all the gems from scratch.Nullification
Does it work without bundle exec?Underestimate
No, it doesn't. bin/rails c produces exactly the same issue.Nullification
N
20

The solution was to add:

require 'action_mailer/railtie'

to config/application.rb, as that file was not doing require 'rails/all.

Nullification answered 10/5, 2016 at 16:53 Comment(2)
I am facing the same error, but I'm getting this new error once I add that line: cannot load such file -- action_mailer/railtie (LoadError)Terbium
Thank you, this fixed it for me. That line was already present, but commented out, in my application.rbIny
P
0

I can't comment so, I answer here I go this error inside Docker container I added following in Dockerfile so it works for me RUN BUNDLE_GEMFILE=Gemfile

Pliam answered 31/5, 2017 at 15:8 Comment(0)
Q
0

I encountered the same problem during the migration of Rails 5.2 to Rails 6.1. The problem was that I had different version of "Railties" gem installed.

So to solve this, after I upgraded gem 'rails' version to 6.1, I also upgraded gem 'railties' to 6.1 too.

Quijano answered 18/11, 2021 at 12:38 Comment(0)
F
0

I had a similar problem (same first line with method_missing) but my issue had a much more prosaic explanation:

For some reason, after I'd switched around/updated my dependencies I had to remove the line

config.action_mailbox.ingress = :relay

from both development and production enviornments.

I'm just including the answer here so anyone else who spends hours trying to fix this finds a potential fix in the result.

Furiya answered 27/2, 2022 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.