2016-04-21 5 views
0

Ich habe ein Problem, bei dem ich E-Mails über den Mailer für ein hartcodiertes Array senden kann. Aber die E-Mail nicht für ein Array von config.ymlruby ​​on rails actionmailer empfängt keine E-Mails an Arrays aus einer yaml-Datei

Hier ist meine config.yml

company: 
    email: 
    - [email protected] 
    - [email protected] 
    - [email protected] 

mein Mailer Klasse Dies ist abgeholt geht durch:

class ReportMailer < ActionMailer::Base 
    default :from => "[email protected]" 


    def send_report(company, file) 

     mail(:to=> "#{CONFIG[company]['email']}", :subject => "Daily Report") 
    end 
    end 
end 

, wenn es ausgeführt in meinem Schienen-Konsole & die Protokolle anzeigen, scheint wie alles wurde gut ausgeführt, aber ich habe meine E-Mail nicht erhalten:

[DEBUG] 2016-04-21 18:21:29 :: Date: Thu, 21 Apr 2016 18:21:29 -0400 
From: [email protected] 
to: ["[email protected]", "[email protected]","[email protected]"] 
... 
... 

[INFO] 2016-04-21 18:21:29 :: 
Sent mail to ["[email protected]", "[email protected]", "[email protected]"] 

Wenn ich meinen Code ändern & Ersetzen Sie es mit hardcoded Array anstelle von config.yml lesen es funktioniert gut.

Liest ich das yaml Array falsch?

+1

Sie sind Passieren string to 'to' hier anstelle eines Arrays – Alfie

Antwort

1

Wie im Kommentar von @Alfie richtig ausgeführt, übergeben Sie ein Array mit Zeichenfolgen an to:.

CONFIG[company]['email'] ein Array zurückgibt, dann String Interpolation ruft to_s darauf und man am Ende mit

"['[email protected]', '[email protected]','[email protected]']" 

im Array passieren einfach, ohne es in eine Zeichenfolge eingefügt:

mail(:to=> CONFIG[company]['email'], :subject => "Daily Report")