したがって、コントローラーメソッドがあります:
def send_feedback
if params[:f_message].length!=0
if current_user && current_user.email
UserMailer.feedback_email(current_user.email, params[:f_name], params[:f_message]).deliver
redirect_to root_url, :notice=>"Thank you for contacting us"
else
UserMailer.feedback_email(params[:f_email], params[:f_name], params[:f_message]).deliver
redirect_to root_url, :notice=>"Thank you for contacting us"
end
else
redirect_to "/info/feedback", :notice=>"Your message is empty... Please be a little bit more informative"
end
end
そして、サーバーはフィードバックフォームの送信にログオンします:
Started POST "/info/send_feedback" for 127.0.0.1 at 2013-06-30 15:50:23 +0400
Processing by InfoController#send_feedback as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"9yht/zb6RqAlpOJeLPTKpAxvINzWAqFJJHkZE+6hv1Q=", "f_email"=>"", "f_name"=>"", "f_message"=>"test" }
(だから私はパラメータを取得してに渡していますfeedback_email
):
def feedback_email(email, name, message)
mail :to => "support@*******.com", :subject => "feedback"
@mail=email
@name=name
@message=message
end
テンプレートあり:
From: <%=@name.inspect %>
Mail: <%= @mail.inspect %>
<%= @message.inspect %>
最後に、メール送信のサーバー ログ:
Sent mail to *** (2045ms)
Date: Sun, 30 Jun 2013 15:50:23 +0400
From: from@example.com
To: support@*******.com
Message-ID: <51d01b7f2a183_15902ec382492cf@HP-PC.mail>
Subject: feedback
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
From: nil
Mail: nil
nil
Redirected to http://localhost:3000/
しかし、それは空です。なんで?