如何在控制器中设置变量作为文件的内容?

时间:2012-02-13 20:02:35

标签: ruby-on-rails ruby-on-rails-3

我有以下文件:

/app/views/admin/newsletters/1_announcement_html.html.erb

在admin控制器中,我想将此文件的内容设置为变量,以允许我将var发送到用户邮件程序。我怎样才能做到这一点?我有:

  def newsletter_deliver
    from = params[:from]
    to = params[:to]
    bcc = params[:bcc]
    subject = params[:subject]

    text = render :file => "admin/newsletters/1_announcement_text.html.erb"
    html = render :file => "admin/newsletters/1_announcement_html.html.erb"

    UserMailer.newsletter(from,to,bcc,subject,html,text).deliver

    render :text => 'Sent'
  end

DoubleRenderError出现此错误。想法?感谢

1 个答案:

答案 0 :(得分:1)

在分配变量时使用render_to_string代替render