I''m writing an auto-responder that handles many email addresses for
many domains for a campaign and need to allow clients to manage the
content of the messages, per-address.
I know I can do this by having methods for each reply in the AM
subclass and having a related ERb template, but that''s really clunky
for my needs and prevents the storage of template content in the db.
I''ve got all the logic worked out and things are going fine, save one
bit.
I have a method sort of like:
def reply(recip, cfg)
@subject = cfg[''subject'']
@recipients = recip
@from = cfg[''from'']
@sent_on = Time.now
@body[''code''] = code
end
What I need is for the @body part to be, if possible, normal ERb
pulled from the DB. I know how to do the pull, have it all set up,
etc. But how do I get the AM to NOT look for the template and instead
use my string for the body, all the while interpolating and
evaluating any Ruby therein?
Possible? I know AM is young and simple, but I''m hoping this is
possible :)
Woops. Typed instead of cutting and pasting. Make that:
def reply(recip, cfg, code)
@subject = cfg[''subject'']
@recipients = recip
@from = cfg[''from'']
@sent_on = Time.now
@body[''code''] = code
end
On Jul 14, 2005, at 6:18 PM, Toby Boudreaux wrote:
> def reply(recip, cfg)
> @subject = cfg[''subject'']
> @recipients = recip
> @from = cfg[''from'']
> @sent_on = Time.now
> @body[''code''] = code
> end
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
On Jul 14, 2005, at 4:18 PM, Toby Boudreaux wrote:> I''m writing an auto-responder that handles many email addresses for > many domains for a campaign and need to allow clients to manage the > content of the messages, per-address. > > I know I can do this by having methods for each reply in the AM > subclass and having a related ERb template, but that''s really > clunky for my needs and prevents the storage of template content in > the db. > > I''ve got all the logic worked out and things are going fine, save > one bit. > > I have a method sort of like: > > def reply(recip, cfg) > @subject = cfg[''subject''] > @recipients = recip > @from = cfg[''from''] > @sent_on = Time.now > @body[''code''] = code > end > > What I need is for the @body part to be, if possible, normal ERb > pulled from the DB. I know how to do the pull, have it all set up, > etc. But how do I get the AM to NOT look for the template and > instead use my string for the body, all the while interpolating and > evaluating any Ruby therein? > > Possible? I know AM is young and simple, but I''m hoping this is > possible :)It is definitely possible, but not really documented. We (the rails core team) need to make it easier to do things like that, but for now try something like the following: def reply(recip, cfg, code) ... @body = initialize_template_class(:code => code).render(:inline => cfg[''template_body'']) end - Jamis
initialize_template_class seems to be missing from ActionMailer 1.0.0 Is there a newer version of doing this? On Jul 14, 2005, at 8:15 PM, Jamis Buck wrote:> On Jul 14, 2005, at 4:18 PM, Toby Boudreaux wrote: > > >> I''m writing an auto-responder that handles many email addresses >> for many domains for a campaign and need to allow clients to >> manage the content of the messages, per-address. >> >> I know I can do this by having methods for each reply in the AM >> subclass and having a related ERb template, but that''s really >> clunky for my needs and prevents the storage of template content >> in the db. >> >> I''ve got all the logic worked out and things are going fine, save >> one bit. >> >> I have a method sort of like: >> >> def reply(recip, cfg) >> @subject = cfg[''subject''] >> @recipients = recip >> @from = cfg[''from''] >> @sent_on = Time.now >> @body[''code''] = code >> end >> >> What I need is for the @body part to be, if possible, normal ERb >> pulled from the DB. I know how to do the pull, have it all set up, >> etc. But how do I get the AM to NOT look for the template and >> instead use my string for the body, all the while interpolating >> and evaluating any Ruby therein? >> >> Possible? I know AM is young and simple, but I''m hoping this is >> possible :) >> > > It is definitely possible, but not really documented. We (the rails > core team) need to make it easier to do things like that, but for > now try something like the following: > > def reply(recip, cfg, code) > ... > @body = initialize_template_class(:code => code).render(:inline > => cfg[''template_body'']) > end > > - Jamis > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Nevermind - I had the wrong version open. :) On Jul 18, 2005, at 5:11 PM, Toby Boudreaux wrote:> initialize_template_class seems to be missing from ActionMailer 1.0.0 > > Is there a newer version of doing this? > > > > > On Jul 14, 2005, at 8:15 PM, Jamis Buck wrote: > > >> On Jul 14, 2005, at 4:18 PM, Toby Boudreaux wrote: >> >> >> >>> I''m writing an auto-responder that handles many email addresses >>> for many domains for a campaign and need to allow clients to >>> manage the content of the messages, per-address. >>> >>> I know I can do this by having methods for each reply in the AM >>> subclass and having a related ERb template, but that''s really >>> clunky for my needs and prevents the storage of template content >>> in the db. >>> >>> I''ve got all the logic worked out and things are going fine, save >>> one bit. >>> >>> I have a method sort of like: >>> >>> def reply(recip, cfg) >>> @subject = cfg[''subject''] >>> @recipients = recip >>> @from = cfg[''from''] >>> @sent_on = Time.now >>> @body[''code''] = code >>> end >>> >>> What I need is for the @body part to be, if possible, normal ERb >>> pulled from the DB. I know how to do the pull, have it all set >>> up, etc. But how do I get the AM to NOT look for the template and >>> instead use my string for the body, all the while interpolating >>> and evaluating any Ruby therein? >>> >>> Possible? I know AM is young and simple, but I''m hoping this is >>> possible :) >>> >>> >> >> It is definitely possible, but not really documented. We (the >> rails core team) need to make it easier to do things like that, >> but for now try something like the following: >> >> def reply(recip, cfg, code) >> ... >> @body = initialize_template_class(:code => code).render >> (:inline => cfg[''template_body'']) >> end >> >> - Jamis >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Jamie (or anyone!)
The bit here is being used:
def reply(recip, code, cfg)
...
@body = initialize_template_class(:code =>
''XXXX'').render
(:inline => cfg[''failure_body''])
...
end
Results in the interpolation failing in cfg[''failure_body''].
I get a returned mail with the following NameError:
/var/www/XXXX/XXXX/script/runner:4: undefined local variable or
method `code'' for #<ActionView::Base:0xb7058ae4> (NameError)
In the template text (cfg[''failure_body'']), I use that as:
<%= code %>
The ActionMailer::Base class isn''t 100% commented and I am tracing
things up to a call to send() and am unsure what the scoop might be.
Ideas?
On Jul 18, 2005, at 5:15 PM, Toby Boudreaux wrote:
> Nevermind - I had the wrong version open.
>
> :)
>
> On Jul 18, 2005, at 5:11 PM, Toby Boudreaux wrote:
>
>
>> initialize_template_class seems to be missing from ActionMailer 1.0.0
>>
>> Is there a newer version of doing this?
>>
>>
>>
>>
>> On Jul 14, 2005, at 8:15 PM, Jamis Buck wrote:
>>
>>
>>
>>> On Jul 14, 2005, at 4:18 PM, Toby Boudreaux wrote:
>>>
>>>
>>>
>>>
>>>> I''m writing an auto-responder that handles many email
addresses
>>>> for many domains for a campaign and need to allow clients to
>>>> manage the content of the messages, per-address.
>>>>
>>>> I know I can do this by having methods for each reply in the AM
>>>> subclass and having a related ERb template, but that''s
really
>>>> clunky for my needs and prevents the storage of template
content
>>>> in the db.
>>>>
>>>> I''ve got all the logic worked out and things are going
fine,
>>>> save one bit.
>>>>
>>>> I have a method sort of like:
>>>>
>>>> def reply(recip, cfg)
>>>> @subject = cfg[''subject'']
>>>> @recipients = recip
>>>> @from = cfg[''from'']
>>>> @sent_on = Time.now
>>>> @body[''code''] = code
>>>> end
>>>>
>>>> What I need is for the @body part to be, if possible, normal
ERb
>>>> pulled from the DB. I know how to do the pull, have it all set
>>>> up, etc. But how do I get the AM to NOT look for the template
>>>> and instead use my string for the body, all the while
>>>> interpolating and evaluating any Ruby therein?
>>>>
>>>> Possible? I know AM is young and simple, but I''m
hoping this is
>>>> possible :)
>>>>
>>>>
>>>>
>>>
>>> It is definitely possible, but not really documented. We (the
>>> rails core team) need to make it easier to do things like that,
>>> but for now try something like the following:
>>>
>>> def reply(recip, cfg, code)
>>> ...
>>> @body = initialize_template_class(:code => code).render
>>> (:inline => cfg[''template_body''])
>>> end
>>>
>>> - Jamis
>>>
>>> _______________________________________________
>>> Rails mailing list
>>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>>
>>>
>>>
>>
>> _______________________________________________
>> Rails mailing list
>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
On Jul 18, 2005, at 3:23 PM, Toby Boudreaux wrote:> Jamie (or anyone!)(Jamis, actually, but that''s not really important)> The bit here is being used: > > def reply(recip, code, cfg) > ... > @body = initialize_template_class(:code => ''XXXX'').render > (:inline => cfg[''failure_body'']) > ... > end > > Results in the interpolation failing in cfg[''failure_body'']. > I get a returned mail with the following NameError: > > > /var/www/XXXX/XXXX/script/runner:4: undefined local variable or > method `code'' for #<ActionView::Base:0xb7058ae4> (NameError) > > In the template text (cfg[''failure_body'']), I use that as: > > <%= code %> > > > The ActionMailer::Base class isn''t 100% commented and I am tracing > things up to a call to send() and am unsure what the scoop might be. >When using :code => ''XXXX'', you need to then refer to ''code'' as an instance variable in the template: <%= @code %> See if that works any better for you. - Jamis
I knew it was Jamis, I swear! Just a typo. You''re entirely correct. Seems one of my editors didn''t use the @ prefix in their copy edits. Thanks! On Jul 18, 2005, at 5:27 PM, Jamis Buck wrote:> On Jul 18, 2005, at 3:23 PM, Toby Boudreaux wrote: > > >> Jamie (or anyone!) >> > > (Jamis, actually, but that''s not really important) > > >> The bit here is being used: >> >> def reply(recip, code, cfg) >> ... >> @body = initialize_template_class(:code => ''XXXX'').render >> (:inline => cfg[''failure_body'']) >> ... >> end >> >> Results in the interpolation failing in cfg[''failure_body'']. >> I get a returned mail with the following NameError: >> >> >> /var/www/XXXX/XXXX/script/runner:4: undefined local variable or >> method `code'' for #<ActionView::Base:0xb7058ae4> (NameError) >> >> In the template text (cfg[''failure_body'']), I use that as: >> >> <%= code %> >> >> >> The ActionMailer::Base class isn''t 100% commented and I am tracing >> things up to a call to send() and am unsure what the scoop might be. >> >> > > When using :code => ''XXXX'', you need to then refer to ''code'' as an > instance variable in the template: > > <%= @code %> > > See if that works any better for you. > > - Jamis > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >