导轨 3 >在 rake 任务中渲染视图 [英] Rails 3 > Rendering views in rake task

查看:30
本文介绍了导轨 3 >在 rake 任务中渲染视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正忙于一项需要为 Mailchimp 准备时事通讯的佣金任务.

I'm stuck with a rake task that need to prepare a newsletter for Mailchimp.

使用 rails 2.x 的东西在谷歌上搜索我现在有这个代码:

Using rails 2.x stuff googled I now have this code:

desc "Sends newsletter to Mailchimp list"
  task :send_newsletter => :environment do
    begin
      # get render helpers
      av = ActionView::Base.new(Rails::Application::Configuration.new(Rails.root).view_path)
      av.class_eval do
        include ApplicationHelper
      end

      things = Stuff.do.things

      h = Hominid::Base.new({:api_key => "xxx"})
      h.create_campaign(
        {
          :list_id => "xxx",
          :subject => "Hey...",
          :from_email => "xxx",
          :from_name => "xxx",
          :to_email => "",
          :auto_footer => true,
          :generate_text => true
        },
        {
          :html => av.render(:template => "stuff/newsletter", :locals => {:things => things}, :layout => false)
        },
        "regular")
    rescue Exception => e
      STDERR.puts ">>> #{e.to_yaml}"
    end

我收到此错误消息:未定义方法 `virtual_path' for false:FalseClass"

And I get this error message: "undefined method `virtual_path' for false:FalseClass"

我的第一次尝试是使用 render_to_string 但我无法访问,因为它在控制器而不是视图中.

My first try was with render_to_string but I just can't access as it is in the controller not the view.

任何帮助将不胜感激:)

Any help would be greatly appreciated :)

推荐答案

:layout =>无 ?

这篇关于导轨 3 >在 rake 任务中渲染视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆