Ruby Forum Ruby on Rails > application helper methods in mailers not available?

Posted by Joshua Muheim (josh)
on 22.10.2008 20:20
Hi all

I have some methods in application.rb and make them accessible to view
using

helper_method :xxx

Sadly they don't seem to be available in mailer templates? Is that
normal? Or did I miss something?

Thanks
Josh
Posted by Frederick Cheung (Guest)
on 23.10.2008 04:37
(Received via mailing list)
On 22 Oct 2008, at 14:20, Joshua Muheim wrote:

>
That's normal. ActionMailer classes don't inherit from
ApplicationController so it is normal that the methods in there do not
magically appear in ActionMailer instances/views.

Fred
Posted by Joshua Muheim (josh)
on 23.10.2008 08:58
Frederick Cheung wrote:
> On 22 Oct 2008, at 14:20, Joshua Muheim wrote:
> 
>>
> That's normal. ActionMailer classes don't inherit from
> ApplicationController so it is normal that the methods in there do not
> magically appear in ActionMailer instances/views.
> 
> Fred

Thanks for your reply. But this seems a little bit strange to me... All 
in all a view is a view, whether it's a "normal" or a mailer's one, 
right?

So what can I do to access my helpers in the mailer's view?

Thanks
Posted by Frederick Cheung (Guest)
on 23.10.2008 16:18
(Received via mailing list)
On Oct 23, 2:58 am, Joshua Muheim <rails-mailing-l...@andreas-s.net>
wrote:
> in all a view is a view, whether it's a "normal" or a mailer's one,
> right?

You're right, it's mostly an infratructure problem here. You just
can't steal methods defined in a completely separate place.
>
> So what can I do to access my helpers in the mailer's view?

One way would be to define them in a module which you include in
ApplicationController and in the mailer (Use the helper method in the
latter).

Fred
Posted by Joshua Muheim (josh)
on 24.10.2008 23:35
Frederick Cheung wrote:
> On Oct 23, 2:58�am, Joshua Muheim <rails-mailing-l...@andreas-s.net>
> wrote:
>> in all a view is a view, whether it's a "normal" or a mailer's one,
>> right?
> 
> You're right, it's mostly an infratructure problem here. You just
> can't steal methods defined in a completely separate place.
>>
>> So what can I do to access my helpers in the mailer's view?
> 
> One way would be to define them in a module which you include in
> ApplicationController and in the mailer (Use the helper method in the
> latter).
> 
> Fred

Thanks for the idea. Where should I put the module?