Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 邮递员:电子邮件是空的,可以';我不明白为什么_Ruby On Rails - Fatal编程技术网

Ruby on rails 邮递员:电子邮件是空的,可以';我不明白为什么

Ruby on rails 邮递员:电子邮件是空的,可以';我不明白为什么,ruby-on-rails,Ruby On Rails,因此,有一种控制器方法: 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=>"

因此,有一种控制器方法:

  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" }
(因此,我正在获取参数并将其传递给
反馈\u电子邮件
):

使用模板:

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/
发送邮件至***(2045ms)
日期:2013年6月30日星期日15:50:23+0400
发件人:from@example.com
致:support@********.com
消息ID:
主题:反馈
Mime版本:1.0
内容类型:文本/纯文本;
字符集=UTF-8
内容传输编码:7bit
发信人:无
邮件:无
无
重定向到http://localhost:3000/

但是,它是空的。为什么?

您必须在发送电子邮件之前设置变量,而不是在以下时间之后:

def feedback_email(email, name, message)
  @mail    = email
  @name    = name
  @message = message

  mail :to => "support@*******.com", :subject => "feedback"
end

您必须在发送电子邮件之前设置变量,而不是在以下时间之后:

def feedback_email(email, name, message)
  @mail    = email
  @name    = name
  @message = message

  mail :to => "support@*******.com", :subject => "feedback"
end

@Misha,我仔细检查了一下,是的,但是mail没有看到变量
@name
@message
@mail
@Misha,我还编辑了,添加了检查变量,查看了输出。关于params。。。我不太确定,请求中没有参数,但它们在服务器日志中作为Parametrs=>{}query@Mischa,我仔细检查了一下,是的,但是mail没有看到变量
@name
@message
@mail
@misha,我还编辑了,添加了检查变量,查看了输出。关于params。。。我不太确定,请求中没有参数,但它们以Parametrs=>{}queryow的形式出现在服务器日志中,谢谢,这将永远需要我自己来解决。。。实际上,顺序或定义变量和调用方法通常并不重要。。。或者我认为这通常很重要
mail
调用使用这些变量的视图,但它们还不存在。因此,电子邮件是空的。我想不出在什么情况下,事后定义变量会起作用。无论如何,很高兴我能帮你解决问题。哇,谢谢,我要花很长时间才能自己解决。。。实际上,顺序或定义变量和调用方法通常并不重要。。。或者我认为这通常很重要
mail
调用使用这些变量的视图,但它们还不存在。因此,电子邮件是空的。我想不出在什么情况下,事后定义变量会起作用。不管怎样,很高兴我能帮你解决问题。