Rails 3 中的邮件助手
我正在尝试获取以下代码:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它说
ActionMailer
继承自AbstractController
。在常规控制器(例如标准示例PostsController
)中,如果不在控制器中明确包含帮助程序,则无法从PostsHelper
或ApplicationHelper
访问方法。例如,默认情况下,您不能在控制器内使用link_to
。因此,如果您想在
Mailer
类中使用此方法,则需要包含 ApplicationHelper
。It says
ActionMailer
inherits fromAbstractController
. In a regular controller (e.g. standard examplePostsController
) you can't access methods fromPostsHelper
orApplicationHelper
without explicitly including the helper in your controller. E.g. By default you cannot uselink_to
inside a controller.So, if you want to use this method inside your
Mailer
class, you need toinclude ApplicationHelper
.