2011-09-07 94 views
2

我設置了ActionMailer 3.x以供在Rails之外使用,但電子郵件沒有正文。誰能幫忙?ActionMailer without Rails - 視圖未被拾取

# ./app.rb 
require 'action_mailer' 
ActionMailer::Base.delivery_method = :file 
ActionMailer::Base.file_settings[:location] = './tmp/mails' 
ActionMailer::Base.view_paths = './views' 

class Mailer < ActionMailer::Base 
    def instructions(email_address) 
    mail(:to => email_address, :subject => 'hello') 
    end 
end 

Mailer.instructions('[email protected]').deliver 

然後我有兩個文件對我的看法,一個純文本

# ./views/mailer/instructions.text.erb 
These are some instructions 

還有一對HTML(使用HAML - 我知道有一些潛在的問題與此,這裏的任何建議是讚賞太)

# ./views/mailer/instructions.html.haml 
%html 
    %body 
    %h1 These are some HTML instructions 

但是,如果我檢查我的新創建./tmp/mails/[email protected]我只有以下,且無正文:

Date: Wed, 07 Sep 2011 18:38:09 +0530 
From: [email protected] 
To: [email protected] 
Message-ID: <[email protected]> 
Subject: hello 
Mime-Version: 1.0 
Content-Type: text/plain; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

任何想法這裏發生了什麼?在此先感謝

+0

你已經解決了這個問題嗎? – hade

回答

1

從Rails 2.x - > 3.x遷移後,我有同樣的問題(雖然有點不同)。我的HTML電子郵件沒有任何內容。我從模型搬到我的郵件類文件夾到文件夾郵寄和改變了我的看法的文件名:

file_name.text.html.erb

=>

file_name.html.erb

希望這有助於。

+0

看起來我需要更改文件名 - 關於 - 謝謝! –