Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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/9/ruby-on-rails-3/4.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_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 如何将数组表单邮件传递给查看?

Ruby on rails 如何将数组表单邮件传递给查看?,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,请帮助传递数组表单邮件以查看 app/mailers/send_mailer.rb: class SendMailer < ApplicationMailer default from: 'no-reply@kalinin.ru' def sends_send(sends, emails, current_user_email) @log = [] @log.push('----------------------------------------------

请帮助传递数组表单邮件以查看

app/mailers/send_mailer.rb:

class SendMailer < ApplicationMailer
  default from: 'no-reply@kalinin.ru'

  def sends_send(sends, emails, current_user_email)
    @log = []

    @log.push('--------------------------------------------------------------------')
    @log.push('send log for ' + current_user_email + ' :: started at ' + Time.now.to_s)

    sends.each do |send|
      emails.each do |email|
        @send = send
        @email = email

        if mail(to: email.email, subject: send.subject)
          @log.push('OK:: email: ' + email.email + ' :: send: ' + send.id.to_s + ' :: send_at: ' + Time.now.to_s)
        else
          @log.push('FAIL:: email: ' + email.email + ' :: send: ' + send.id.to_s + ' :: send_at: ' + Time.now.to_s)
        end
      end  
    end  
    puts @log
  end  
end
按下主页上的按钮后,执行操作“发送邮件”并执行发送邮件.rb。数组@log已填充并输出到控制台。但我需要显示@log-into-view。但现在的视图是空的

app/views/log/index.rb:

<h1>Log#index</h1>
<%= @log %>
耙道:

log_index GET    /log/index(.:format)                      log#index

请帮助将@log传递到视图中。

在模型方法中定义的实例变量在调用该模型方法的控制器或任何其他类中都不可用。但是,如果需要,可以在方法末尾返回变量的值,然后确保将其他变量设置为该值。例如,在您的
sends\u sends
(这是一个名称非常混乱的方法btw)方法中,将最后一行从
put@log
更改为
@log

然后在控制器中,更改

SendMailer.sends_send(@sends, @emails, current_user.email).deliver_now


在模型方法中定义的实例变量在控制器或调用该模型方法的任何其他类中都不可用。但是,如果需要,可以在方法末尾返回变量的值,然后确保将其他变量设置为该值。例如,在您的
sends\u sends
(这是一个名称非常混乱的方法btw)方法中,将最后一行从
put@log
更改为
@log

然后在控制器中,更改

SendMailer.sends_send(@sends, @emails, current_user.email).deliver_now


在模型方法中定义的实例变量在控制器或调用该模型方法的任何其他类中都不可用。但是,如果需要,可以在方法末尾返回变量的值,然后确保将其他变量设置为该值。例如,在您的
sends\u sends
(这是一个名称非常混乱的方法btw)方法中,将最后一行从
put@log
更改为
@log

然后在控制器中,更改

SendMailer.sends_send(@sends, @emails, current_user.email).deliver_now


在模型方法中定义的实例变量在控制器或调用该模型方法的任何其他类中都不可用。但是,如果需要,可以在方法末尾返回变量的值,然后确保将其他变量设置为该值。例如,在您的
sends\u sends
(这是一个名称非常混乱的方法btw)方法中,将最后一行从
put@log
更改为
@log

然后在控制器中,更改

SendMailer.sends_send(@sends, @emails, current_user.email).deliver_now


仅供参考,最好是在{Time.now.to{s}开始,而不是为{code>'当前用户{e-mail+发送日志:::开始于{Time.现在。to{s}更易读、更简洁、更不脆弱。仅供参考,最好是在{code>开始为}当前用户{e-mail+发送日志#{Time.now.to_s}而不是
'为当前用户发送日志\电子邮件+::开始于“+Time.now.to_s
-它更可读、更简洁、更不脆弱。仅供参考,最好是
为当前用户发送日志\电子邮件::开始于{Time.now.to}”
而不是
“为当前用户发送日志”+电子邮件+::从“+时间开始。现在。发送到”
-它更可读、更简洁、更不脆弱。仅供参考,最好是执行
“为当前用户发送日志:”从{时间开始。现在。发送到}”
而不是
'send log for'+current_user_email+'::从“+时间开始。现在。to_
-它更可读、更简洁、更不脆弱。但是
code
@log=SendMailer.send_send(@sends,@emails,current_user.email)。立即发送\u
code
code
输出
code
Mail::Message
code
。没有日志。很抱歉,我无法理解您的评论。但是
code
@log=SendMailer.send\u发送(@sends,@email,current\u user.email)。立即发送\u
code
code
输出
code
Mail::Message
code
。没有日志。很抱歉,我无法理解您的评论。但是
code
@log=SendMailer.send\u发送(@sends,@email,current\u user.email)。立即发送\u
code
code
输出
code
Mail::Message
code
。没有日志。很抱歉,我无法理解您的评论。但是
code
@log=SendMailer.send\u发送(@sends,@email,current\u user.email)请立即交付_
code
code
输出
code
Mail::Message
code
。没有日志。很抱歉,我无法理解您的评论。