您的位置:首页 > 大数据 > 人工智能

How to use my view helpers in my ActionMailer views?

2010-12-15 19:56 956 查看

How to use my view helpers in my ActionMailer views?





up vote3down votefavoriteI want to use the methods I defined in
app/helpers/annotations_helper.rb
in my ReportMailer views (
app/views/report_mailer/usage_report.text.html.erb
). How do I do this?

Based on this guide it seems like the
add_template_helper(helper_module)
method might do what I want, but I can't figure out how to use it.

(BTW, is there a reason you get access to a different set of helpers in mailer views? This is pretty annoying.)

ruby-on-rails
link|flagasked Sep 13 '09 at 6:02

Horace Loeb
2,4041648
67% accept rate

2 Answers

activenewestvotes

up vote6down voteacceptedIn the model class that you are using to manage your emails:

class ReportMailer < ActionMailer::Base
add_template_helper(AnnotationsHelper)

...
end
link|flaganswered Sep 13 '09 at 22:04

Mark Connell
2364
That's easy enough! – Horace Loeb Sep 15 '09 at 2:10




up vote0down voteThis might give you some direction, I have a method "check_options" defined in "app/helpers/app_helper.rb"

In my controller that renders the view "app/controllers/app_controller.rb" I have the following line

helper: all # include all the helpers all the time
and then finally in my view I just call the "check_options" like

<% if check_options ...
From the documentation link that you posted looks like you might need

helper(*args, &block)

Declare a helper:
"helper :foo"  requires ‘foo_helper’ and includes FooHelper in the template class.
Give this link a try as well http://caboo.se/doc/classes/ActionController/Helpers/ClassMethods.html there are some examples that might help

A small excerpt from the page

"By default, the controller will include a helper whose name matches that of the controller, e.g., MyController will automatically include MyHelper."

Cheers

link|flaganswered Sep 13 '09 at 6:47

Anand
1,7851620
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐