我是action_mailer的新手,我不知道会出现什么问题。过去12个小时我一直在圈子里。它可能是一个宝石依赖,它可能是我做错了。请帮忙!
邮件在我的本地环境中工作,但我无法推送到heroku。我一直收到这个错误:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
NoMethodError: undefined method `action_mailer' for #<Rails::Application:
:Configuration:0x00000002fad208>
在将版本添加到GEM文件后编辑新错误
Running: rake assets:precompile
I, [2014-04-01T14:00:22.863048 #796] INFO -- : Writing /tmp/build_a1da56
f1-c7f3-455c-9bea-c9bf4306ef11/public/assets/blank_tan_vig-03e2648e62e03d21bb6cb
8e57937edf8.jpg
I, [2014-04-01T14:00:22.865246 #796] INFO -- : Writing /tmp/build_a1da56
f1-c7f3-455c-9bea-c9bf4306ef11/public/assets/rails-5c3c576fb6f357c0c4d2a32214da4
4b6.png
I, [2014-04-01T14:00:27.585107 #796] INFO -- : Writing /tmp/build_a1da56
f1-c7f3-455c-9bea-c9bf4306ef11/public/assets/application-bc6a900b1f1dc90eba371ab
1e65adb36.js
rake aborted!
NoMethodError: undefined method `environment' for nil:NilClass
我正在尝试将Mandrill用于我的SMTP服务器。我已经安装并正确配置了heroku插件(据我所知)。我遵循了这个:https://devcenter.heroku.com/articles/mandrill
user_mailer文件:
class UserMailer < ActionMailer::Base
default from: "info@myflix.com"
def send_welcome_email(user)
@user = user
mail(to: @user.email, subject: "Welcome to Myflix!")
end
end
生产环境
Myflix::Application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.mandrillapp.com',
:port => 587,
:user_name => ENV['MANDRILL_USERNAME'],
:password => ENV['MANDRILL_APIKEY'], # SMTP password is any valid API key
:domain => 'heroku.com', # your domain to identify your server when connecting
:authentication => 'plain' # Mandrill supports 'plain' or 'login'
}
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
的Gemfile:
来源'https://rubygems.org' 红宝石'1.9.3'
gem 'bootstrap-sass'
gem 'coffee-rails'
gem 'rails', '4.0.0'
gem 'haml-rails'
gem 'sass-rails'
gem 'uglifier'
gem 'jquery-rails'
gem 'bootstrap_form'
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'fabrication'
gem 'faker'
group :development do
gem 'sqlite3'
gem 'pry'
gem 'pry-nav'
gem 'thin'
gem 'better_errors'
gem 'binding_of_caller'
gem 'letter_opener'
end
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'shoulda-matchers'
gem 'capybara'
gem 'launchy'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
答案 0 :(得分:0)
指定您在Gemfile
例如,如果您使用Rails 3.2.13:
gem 'rails', '3.2.13'
或者如果你使用Rails 4
gem 'rails', '4.0.0'
`
运行bundle install
希望有效。
答案 1 :(得分:0)
这是一个依赖性问题。感谢@Abednego,我在我的宝石文件中添加了rails版本,当我得到一个新的错误时,我研究了这个并发现它是sass-rails的依赖问题。新的gemfile如下:
source 'https://rubygems.org'
ruby '1.9.3'
gem 'bootstrap-sass'
gem 'coffee-rails'
gem 'rails', '4.0.0'
gem 'haml-rails'
gem 'sass-rails', "4.0.2"
gem 'uglifier'
gem 'jquery-rails'
gem 'bootstrap_form'
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'fabrication'
gem 'faker'
group :development do
gem 'sqlite3'
gem 'pry'
gem 'pry-nav'
gem 'thin'
gem 'better_errors'
gem 'binding_of_caller'
gem 'letter_opener'
end
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'shoulda-matchers'
gem 'capybara'
gem 'launchy'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end