我是靠谱客的博主 尊敬巨人,最近开发中收集的这篇文章主要介绍How to use my view helpers in my ActionMailer views?How to use my view helpers in my ActionMailer views?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

How to use my view helpers in my ActionMailer views?

up vote 3 down vote favorite

I 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.)

link | flag

67% accept rate

2 Answers

active newest votes
up vote 6 down vote accepted

In the model class that you are using to manage your emails:

class ReportMailer < ActionMailer::Base
  add_template_helper
(AnnotationsHelper)

 
...
end
link | flag
That's easy enough! –  Horace Loeb  Sep 15 '09 at 2:10

up vote 0 down vote

This 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 | flag
  

最后

以上就是尊敬巨人为你收集整理的How to use my view helpers in my ActionMailer views?How to use my view helpers in my ActionMailer views?的全部内容,希望文章能够帮你解决How to use my view helpers in my ActionMailer views?How to use my view helpers in my ActionMailer views?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部