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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2008-10-22 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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-23 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
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2008-10-23 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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-10-23 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
Fc582698581884352e745d1d4c64699d?d=identicon&s=25 Joshua Muheim (josh)
on 2008-10-24 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?
2bccfee95d8478a7f43cbb9cb2a7c959?d=identicon&s=25 Al Iv (alex3119)
on 2009-05-13 13:42
(Received via mailing list)
Just include in your mailer model

helper :application

for example:
class MessageMailer < ActionMailer::Base

  helper :application

  def sent(message)
     ...
  end
end
On Oct 25 2008, 12:35 am, Joshua Muheim <rails-mailing-l...@andreas-
Fbd9cb107fe7c941333d6a3488691989?d=identicon&s=25 Ramon Tayag (ramontayag)
on 2009-10-25 17:19
It seems helper :helper_name doesn't work anymore (2.3.4)

You can use include instead:

class Mailer < AM::Base
  include CoolHelper
  ....
end

Al Iv wrote:
> Just include in your mailer model
>
> helper :application
>
> for example:
> class MessageMailer < ActionMailer::Base
>
>   helper :application
>
>   def sent(message)
>      ...
>   end
> end
> On Oct 25 2008, 12:35�am, Joshua Muheim <rails-mailing-l...@andreas-
Fbd9cb107fe7c941333d6a3488691989?d=identicon&s=25 Ramon Tayag (ramontayag)
on 2009-10-25 17:27
(Received via mailing list)
Actually, I'm mistaken. I didn't read the post properly.

You use include if you want it available in the class itself, then
helper :helper_name if you want it available in the views.

Ramon Tayag



On Mon, Oct 26, 2009 at 12:19 AM, Ramon Tayag
This topic is locked and can not be replied to.