Rails 3 中的邮件助手

发布于 2024-12-18 17:30:43 字数 505 浏览 2 评论 0原文

我正在尝试获取以下代码:

module ApplicationHelper
  def make_email(full_name, email_name)
    @email = full_name + " <" + email_name + "@" + DOMAIN + ">"
  end
end

在我的 Mailer(ActionMailer 类)中看到。我从这里理解 http://edgeguides.rubyonrails.org/action_mailer_basics.html #using-action-mailer-helpers 这应该可以工作,但是邮件程序实际上看不到该函数,并且我收到一个未定义的错误。

我做错了什么/我可以做得更好吗?

I'm trying to get the following code:

module ApplicationHelper
  def make_email(full_name, email_name)
    @email = full_name + " <" + email_name + "@" + DOMAIN + ">"
  end
end

to be seen inside my Mailer (ActionMailer class). I understand from here http://edgeguides.rubyonrails.org/action_mailer_basics.html#using-action-mailer-helpers
that this should work, however the mailer can't actually see the function, and I get an undefined error.

What am I doing wrong/what could I do better?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从来不烧饼 2024-12-25 17:30:43

它说 ActionMailer 继承自 AbstractController。在常规控制器(例如标准示例 PostsController)中,如果不在控制器中明确包含帮助程序,则无法从 PostsHelperApplicationHelper 访问方法。例如,默认情况下,您不能在控制器内使用link_to

因此,如果您想在 Mailer 类中使用此方法,则需要包含 ApplicationHelper

It says ActionMailer inherits from AbstractController. In a regular controller (e.g. standard example PostsController) you can't access methods from PostsHelper or ApplicationHelper without explicitly including the helper in your controller. E.g. By default you cannot use link_to inside a controller.

So, if you want to use this method inside your Mailer class, you need to include ApplicationHelper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文