I have a custom template file that resides in a non-standard (for RoR) 
location.  I wish to use this template for text format messages generated 
by a stand-alone script.  I also wish to incorporate it into a new RoR app 
that is related to the existing script.  The mailer and templates reside in 
this directory structure:

lib
├── hll_action_mailer
│   ├── hll_action_mailer.rb
│   ├── hll_th_forex_mailer
│   │   ├── hll_th_forex_cacb_update_notice.rb
│   │   ├── hll_th_forex_mailer.rb
│   │   └── views
│   │       ├── hll_th_forex_cacb_update_notice.text.erb
│   │       └── hll_th_forex_commercial_rates_notice.text.erb

I have discovered that passing a do block after the call to the mail method 
discards any template_path and template_name keys passed in the argument 
list. See: https://github.com/rails/rails/pull/18412.  However I cannot 
seem to discover any way at all to use my custom template path and name 
with a do block.

I have tried this:



    this_template_name = "hll_th_forex_commercial_rates_notice.text.erb"
    this_template = File.join(  "/", File.dirname( __FILE__ ),
                                "/views",
                                this_template_name )
    mail( :to => recipients,
          :from => fm_address,
          :subject => subject,
        ) \
        do |format|
          format.text do
            render( this_template )
          end
        end


But this causes this error:

     Missing template 
home/byrnejb/Projects/Software/theHeart/code/hll_th_main/lib/hll_action_mailer/hll_th_forex_mailer/views/hll_th_forex_commercial_rates_notice.text.erb
 
with {:locale=>[:en], :formats=>[:text], :variants=>[], :handlers=>[:erb, 
:builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
        * 
"/home/byrnejb/Projects/Software/theHeart/code/hll_th_main/lib/hll_action_mailer/hll_th_forex_mailer"
        * 
"/home/byrnejb/Projects/Software/theHeart/code/hll_th_main/app/views"

I considered the lack of a leading / on the reported path as the source of 
the problem but an inspection of the contents of this_template immediately 
before the call to render shows this:

        do |format|
          format.text do
puts( this_template.inspect )
            render( this_template )
          end
        end

which gives:

"/home/byrnejb/Projects/Software/theHeart/code/hll_th_main/lib/hll_action_mailer/hll_th_forex_mailer/views/hll_th_forex_commercial_rates_notice.text.erb"

So what is happening inside render?  How do I specify a mailer template in 
a non-standard location in render or is that not possible and I must set an 
explicit default?  well that does not work either:

class HllThForexMailer < ActionMailer::Base
  default( :template_path => Pathname.new(
      File.join( File.dirname( __FILE__ ), "views" )
                ).realpath.to_s
                        )
. . . 
    mail( :to => recipients,
          :from => fm_address,
          :subject => subject,
          :template_name => "hll_th_forex_commercial_rates_notice.text.erb"
        )



gives this:

      Missing template 
/home/byrnejb/Projects/Software/theHeart/code/hll_th_main/lib/hll_action_mailer/hll_th_forex_mailer/views/hll_th_forex_commercial_rates_notice.text.erb
 
with "mailer". Searched in:
        * 
"/home/byrnejb/Projects/Software/theHeart/code/hll_th_main/lib/hll_action_mailer/hll_th_forex_mailer/views"

Which is at least what I expected.  However the message says that it cannot 
find the template file.  Yet when I do this using the exact path string 
copied from the 'Missing template message' I see this:

ls -l 
/home/byrnejb/Projects/Software/theHeart/code/hll_th_main/lib/hll_action_mailer/hll_th_forex_mailer/views/hll_th_forex_commercial_rates_notice.text.erb

-rw-rw-r--. 1 byrnejb byrnejb 2010 Oct 20 16:10 
/home/byrnejb/Projects/Software/theHeart/code/hll_th_main/lib/hll_action_mailer/hll_th_forex_mailer/views/hll_th_forex_commercial_rates_notice.text.erb


So something is seriously screwed up with either what action-mailer is 
doing or with the error message it is reporting since the template file is 
exactly where AM says it could not find it.

How do I get this to work?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/cfa34488-d485-409d-91c4-24ce76b30b9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to