未初始化的常量ActionView :: TemplateHandler

时间:2014-08-27 15:31:41

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

我正在将rails项目从rails 2.3.5升级到rails 3.2

我有一些插件代码如下

module SpreadsheetOnRails

  class Handler < ::ActionView::TemplateHandler
  include ActionView::TemplateHandlers::Compilable

  def compile(template)
    %Q{controller.response.content_type ||= Mime::XLS
       controller.headers["Content-Disposition"] = "attachment"
       SpreadsheetOnRails::Base.new { |workbook| #{template.source} }.process}
  end

  end

  class Base
    @@temp_file = nil

    def temp_file_path
      unless @@temp_file
        temp = Tempfile.new('spreadsheet-', File.join(RAILS_ROOT, 'tmp') )
        @@temp_file = temp.path
        temp.close
      end
      @@temp_file
    end

    def initialize
      yield workbook
   end

    def workbook
      @workbook ||= Spreadsheet::Workbook.new
    end

    def process
      workbook.write(temp_file_path)
      File.open(temp_file_path, 'rb') { |file| file.read }
    end
  end
end

在运行rails时我遇到以下错误:

  

未初始化的常量ActionView :: TemplateHandler(NameError)

任何人请帮助如何重新编码此方法,以便它可以兼容rails 3.2

1 个答案:

答案 0 :(得分:0)

在Rails 2.3.8之后,

ActionView::TemplateHandler被弃用。

http://apidock.com/rails/ActionView/TemplateHandler

这意味着TemplateHandler类中的所有功能都已删除或移动到Rails 3.2中的其他类。您将不得不删除引用,因为它已不再定义。

在Rails 2.3.5中查看actionpack/lib/action_view/template_handler.rb。它将帮助您识别在Rails 3.2中需要跟踪的任何功能。

相关问题