我創建一個HTML表格,然後用郵件寶石發送它,並得到了一些意想不到的HTML標籤的輸出是這樣的:紅寶石「郵件」寶石和損壞的HTML電子郵件
< /tr>
DAY PRODUCT_CODE USAGE_TYPE LATE_ARRIVING_USAGE PERCENT
27-SEP-14 sdfgdfg sdfgdf 0.001 0.000%
27-SEP-14 sdfgdg gfdgs 0.1 39 0.000%
27-SEP-14 sdfgdg sdfgdsfg 0.001 0.000%
UPDATE:在對在'HERE'下面循環,如果我在tr之後但在引號內部放置了'ANYTHING'之類的東西,那麼表格頂部的左tr將變成'ANYTHING'並且tr消失。這是怎麼發生的?
我不知道tr標籤是如何到達那裏的。根據我如何連接字符串,其他的字符串會顯示爲td樣式......但我現在的做法只有那個額外的tr標籤。 for循環:
def get_file_as_html(filename)
begin
data = ""
if @has_report_header == "Y" && @report_header != ""
data = "</br><table border =\"1\" style=\"border-width: 1px; border-style: solid;\"><tr>"
data_row = @report_header.split(",")
data_row.each_with_index do |elem,idx|
str = elem.gsub("\"","").strip
data += "<th style= 'align: center; width: 100;'>#{str}</th>"
end
data += "</tr>" # HERE --> "</tr>ANYTHING"
end
data_file = CSV.read(filename, { :col_sep => "\t" , :quote_char => '"' })
#puts data_file
data_file.each do |data_row|
new_data_row = "<tr>"
data_row.each_with_index do |elem,idx|
new_data_row += "<td style= 'text-align: left;align:left; width: 100;'>#{elem}</td>"
end
new_data_row += "</tr>"
data += new_data_row
end
table_footer = "</table></br></br>"
data += table_footer
return data
rescue Exception => e
raise "PROBLEM_IN_HTML_REPORT_GENERATION"
end
end
我把'data'變量放到控制檯,然後放到小提琴裏,看起來很完美。當我發送content_type爲'text/html'時:
def send_attachment(filename,s3url,job_instance_id)
activity_id = get_activity_info(job_instance_id)
recipient_list = get_recipient_list()
my_body_is_ready = get_file_as_html(filename)
mail = Mail.deliver do
to '[email protected]'
from '[email protected]'
subject @subject
text_part do
body 'This is plain text'
end
html_part do
content_type 'text/html; charset=UTF-8'
body my_body_is_ready
end
end
puts mail.to_s #=>
end
任何人都知道什麼可能會破壞消息?謝謝, Tim
如果您不需要get_file_as_html中的'begin'和'end',你可以做'def ... rescue ... end'。 – Max 2014-10-03 20:35:54
好的。但這並不能幫助我。 – Tim 2014-10-03 21:41:18