【发布时间】:2014-09-25 20:35:01
【问题描述】:
当我尝试在生产中为我的应用注册新用户时出现以下错误。我已经阅读了所有其他具有相同错误的 stackoverflow 问题,并且我已经尝试了他们的所有解决方案,但到目前为止没有一个对我有用。
错误:
ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
我在 production.rb 文件中使用我自己的应用名称正确设置了此代码:
config.action_mailer.default_url_options = { host: 'myapp.herokuapp.com' }
这是完整的 production.rb 文件:
Blocipedia::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
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.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.action_mailer.default_url_options = { host: 'myapp.herokuapp.com' }
end
我仔细检查了我已将 Sendgrid 配置为 Heroku 中的附加组件。我的密钥和密码是正确的。
任何建议将不胜感激!谢谢!
编辑:我正在使用 Devise 进行用户身份验证。我不确定该错误所指的邮件模板文件到底是哪个文件,但我猜它是新的注册视图,然后是与此错误相关的邮件确认说明视图,对吗?他们在这里:
新的注册视图:
<h2>Sign up</h2>
<div class="row">
<div class="col-md-8">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, autofocus: true, class: 'form-control', placeholder: "Enter name" %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control', placeholder: "Enter email" %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control', placeholder: "Enter password" %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation, class: 'form-control', placeholder: "Enter password confirmation" %>
</div>
<div class="form-group">
<%= f.submit "Sign up", class: 'btn btn-success' %>
</div>
<div class="form-group">
<%= render "devise/shared/links" %>
</div>
<% end %>
</div>
</div>
及确认说明查看:
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
这是整个错误跟踪日志:
Rendered devise/registrations/new.html.erb within layouts/application (3.3ms)
2014-09-24T23:38:38.136606+00:00 heroku[router]: at=info method=GET path="/users/sign_up" host=blocipedia.herokuapp.com request_id=f52c96a7-014c-4667-b1b3-93e8b47e4364 fwd="70.197.237.94" dyno=web.1 connect=2ms service=12ms status=304 bytes=850
2014-09-24T23:38:48.250414+00:00 app[web.1]: Started POST "/users" for 70.197.237.94 at 2014-09-24 23:38:48 +0000
2014-09-24T23:38:48.347819+00:00 app[web.1]: Completed 500 Internal Server Error in 95ms
2014-09-24T23:38:48.349962+00:00 app[web.1]:
2014-09-24T23:38:48.349966+00:00 app[web.1]:
2014-09-24T23:38:48.349969+00:00 app[web.1]: 2:
2014-09-24T23:38:48.347813+00:00 app[web.1]: Completed 500 Internal Server Error in 95ms
2014-09-24T23:38:48.349959+00:00 app[web.1]: 5: <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
2014-09-24T23:38:48.349972+00:00 app[web.1]: 4:
2014-09-24T23:38:48.349974+00:00 app[web.1]: app/views/devise/mailer/confirmation_instructions.html.erb:5:in `_app_views_devise_mailer_confirmation_instructions_html_erb___2772878935586456441_70136789435480'
2014-09-24T23:38:48.349977+00:00 app[web.1]:
2014-09-24T23:38:48.252507+00:00 app[web.1]: Processing by Devise::RegistrationsController#create as HTML
2014-09-24T23:38:48.349953+00:00 app[web.1]: ActionView::Template::Error (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
【问题讨论】:
-
电子邮件是作为后台作业发送还是在请求期间发送?如果是后台作业(例如,通过 Heroku Scheduler 运行 rake 任务),请确保将环境正确设置为生产环境。
标签: ruby-on-rails heroku