【问题标题】:Where to put mailer class in my Ruby on Rails app?在我的 Ruby on Rails 应用程序中将邮件程序类放在哪里?
【发布时间】:2015-03-02 14:56:57
【问题描述】:

我在我的 Ruby On rails 应用程序中添加了邮戳。我按照页面 https://devcenter.heroku.com/articles/postmark#sending-emails-in-ruby-on-rails-3-x 中的步骤进行操作。现在我需要添加以下代码:

class SuperMailer < ActionMailer::Base

  def email
    from       "test@domain.com"
    subject    "Hello"
    recipients "myemail@domain.com"
    tag        "big-bang"   end

end

但是,我不知道在哪里添加这个类,以及如何使用它。我是否将其添加到我的应用程序模块的 application.rb 文件中?

我如何使用这个类在提交后发送电子邮件(即当有人按下提交时)? 我在我的 static_pages 的 app > views 下的 html 文件中使用提交按钮编写了表单 我要执行以下操作吗?

<form name="contactform" method="post" > ...

【问题讨论】:

    标签: html ruby-on-rails email heroku postmark


    【解决方案1】:

    Action Mailer Rails Guide 是这方面最好最全面的指南 - 它易于阅读,值得您花时间阅读。

    至于您的问题 - 回答太模糊(您在这里提出了多个问题,而不仅仅是一个)- 但在这种情况下,所有答案都在 Rails 指南中。

    但对于一个:您将邮件放在app/mailers 目录中 第二:你必须为你的表单动作设置一个控制器动作,例如:SuperMailer.email.deliver

    但实际上:阅读指南它将回答您的问题

    【讨论】:

    • 谢谢!这很有帮助。下一次,我会在帖子中提出一个问题。
    猜你喜欢
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多