开发者

Rails 3 > Rendering views in rake task

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

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 开发者_如何学Python=> e
      STDERR.puts ">>> #{e.to_yaml}"
    end

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

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 => nil ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜