Rails环境配置:`method_missing':未定义的方法`action_mailer'

时间:2016-05-10 16:04:41

标签: ruby-on-rails ruby-on-rails-4 rubygems bundle actionmailer

尝试调用Rails控制台(bundle exec rails c)或Rails服务器(bundle exec rails s)会导致抛出以下异常:

~/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'
...

我在这里或那里遗漏了一些可能导致不兼容问题的宝石吗?

这是config/environments/development.rb中的违规行:

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

以下是我的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

2 个答案:

答案 0 :(得分:9)

解决方案是添加:

require 'action_mailer/railtie'

config/application.rb,因为该文件没有require 'rails/all

答案 1 :(得分:0)

我不能发表评论,我在这里回答 我在Docker文件中添加了这个错误,我在Dockerfile中添加了以下内容,因此它适用于我     RUN BUNDLE_GEMFILE=Gemfile