[英]Mailer helpers in Rails 3
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). 可以在我的Mailer内部看到(ActionMailer类)。 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. 我从这里了解到http://edgeguides.rubyonrails.org/action_mailer_basics.html#using-action-mailer-helpers应该起作用,但是邮件程序实际上看不到该功能,并且出现了未定义的错误。
What am I doing wrong/what could I do better? 我在做错什么/我能做得更好?
It says ActionMailer
inherits from AbstractController
. 它说ActionMailer
从AbstractController
继承。 In a regular controller (eg standard example PostsController
) you can't access methods from PostsHelper
or ApplicationHelper
without explicitly including the helper in your controller. 在常规控制器(例如标准示例PostsController
)中,如果未在控制器中明确包含帮助器,则无法从PostsHelper
或ApplicationHelper
访问方法。 Eg By default you cannot use link_to
inside a controller. 例如,默认情况下,您不能在控制器内部使用link_to
。
So, if you want to use this method inside your Mailer
class, you need to include ApplicationHelper
. 因此,如果要在Mailer
类中使用此方法,则需要include ApplicationHelper
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.