我无法使用ruby on rails

时间:2016-11-05 05:12:08

标签: ruby-on-rails ruby heroku

我花了最后4个小时才尝试不同的东西来弄清楚为什么我在heroku上发生的电子邮件和错误正在发生。我是Rails的新手这是我的第二个应用程序,所以请把它愚蠢地跟我说话,就像一个小孩子,哈哈,

http://dev-match-matt-napper.herokuapp.com/contacts/new 这是我的heroku链接,当你点击提交它说出错了。我正在关注udemy视频的simpleCodeCast,但他还没有回复。

https://github.com/Mnapper3/simpleCodeCasts_saas 这是我的git hub我使用的文件(主)是:

app/controller/contacts_controller
app/mailers/contact_mailer
app/models/contact
app/contact_mailer/contact_email.html
app/views/contacts/new.html

真的希望我已经给了你足够的信息来帮助我,或者你可能会介绍如何创建表单电子邮件?或链接视频

P.S。即时通讯使用cloud9&如果您克隆此应用程序,则需要:

bundle install
bundle update
rake db:migrate

然后你就可以预览它了。

请帮忙!!!
-Matt Napper

1 个答案:

答案 0 :(得分:0)

您需要在/config/environments/production.rb中添加邮件程序配置,因为heroku默认在生产模式下运行。

在/config/environments/production.rb

中添加
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
  <div class = "row text-center">
    <h2>Cat Photo Finder</h2>
  </div>
  <div class = "row text-center">
    <div class = "col-xs-12 well message">
      The message will go here
    </div>
  </div>
  <div class = "row text-center">
    <div class = "col-xs-12">
      <button id = "getMessage" class = "btn btn-primary">
        Get Message
      </button>
    </div>
  </div>
</div>

然后在/config/secrets.yml中,在生产块中添加以下内容,如

config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: Rails.application.secrets.domain_name,
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: Rails.application.secrets.email_provider_username,
  password: Rails.application.secrets.email_provider_password
}

# ActionMailer Config
config.action_mailer.default_url_options = { :host => Rails.application.secrets.domain_name }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false

最后,您必须在heroku应用上添加这3个环境变量。要添加它们,请转到您的heroku应用设置页面,我假设它应该是https://dashboard.heroku.com/apps/dev-match-matt-napper/settings

在那里,您将看到一个Reveal Config Vars按钮,单击该按钮并添加Key作为您的环境变量和值作为其值。例如:

键是:GMAIL_USERNAME

价值是:您的Gmail电子邮件地址