【发布时间】:2016-07-01 06:34:22
【问题描述】:
Heroku 在邮件程序/Sendgrid 之后无法安装我的应用程序。我得到的错误是:
remote:移除 sprockets-rails (3.0.4) 远程:-----> 为 Rails 资产管道准备应用程序 远程:运行:耙资产:预编译 远程:rake 中止! 远程:NameError:未初始化的常量邮件
它使用 gmail 在本地环境中工作。
邮件功能是在文章发表评论时向管理员发送电子邮件,并在文章发表后向“关注者”发送电子邮件。
app/mailers/commentmailer.rb
class CommentMailer < ActionMailer::Base
def comment_created(评论,文章) @comment = 评论 @article = 文章
mail( to: @article.user.email ,
from:'no_reply@gmail.com' ,
subject:'A comment on your post.')
结束 结束
app/mailers/article_mailer
class ArticleMailer < ActionMailer::Base
def article_created(关注者,文章) @article = 文章 follower.each 做 |f| 邮寄至:f.email,发件人:'no_reply@gmail.com',主题:“已创建文章” 结尾 结尾 结束
views/followers/new.html.erb
<h3> Stay up tp date with my new articles </h3>
<p> You will be sent an email whenever a new article was posted </p>
<%= form_for @follower do |f| %>
<%= f.label :name, "Your Name:" %>
<%= f.text_field :name %>
<br>
<%= f.label :email %>
<%= f.text_field :email %>
<br>
<%= f.submit('Follow me') %>
<% end %>
config/environments/production.rb
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
config.action_mailer.default_url_options = { host: "https://personal-blog22.herokuapp.com " }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true }
config/environments/development.rb
# For better error to work on Vagrant VM
BetterErrors::Middleware.allow_ip! "0.0.0.0/0"
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.consider_all_requests_local
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_controller.perform_caching = false
end
配置/应用程序
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
module PersonalBlog
class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "ruby.blog100.com",
user_name: "XXXXXXgmail.com",
password: "XXXXX",
authentication: :plain,
enable_starttls_auto: true
}
end
end
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 heroku sendgrid