尝试从Rails 3.2.13中的ActionView :: Template :: Handler继承时出错

时间:2014-05-21 15:55:14

标签: ruby-on-rails ruby-on-rails-3.2 railtie kramdown

我尝试从Rails 3.0.23升级到3.2.13,现在我在启动服务器时遇到错误,如下所示:

/Users/hamiltonchapman/Projects/project-static/lib/markdown_handler.rb:3:in `<top (required)>': uninitialized constant ActionView::Template::Handler (NameError)
  from /Users/hamiltonchapman/Projects/project-static/config/environment.rb:9:in `<top (required)>'
  from /Users/hamiltonchapman/Projects/project-static/config.ru:5:in `require'
  from /Users/hamiltonchapman/Projects/project-static/config.ru:5:in `block in <main>'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
  from /Users/hamiltonchapman/Projects/project-static/config.ru:in `new'
  from /Users/hamiltonchapman/Projects/project-static/config.ru:in `<main>'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
  from /Users/hamiltonchapman/.rvm/gems/ruby-2.1.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
  from script/rails:9:in `require'
  from script/rails:9:in `<main>'

导致此问题的代码如下所示:

require 'kramdown'

class MarkdownHandler < ActionView::Template::Handler
  def self.call(template)
    new.render(template, nil)
  end

  def render(template, local_assigns)
    %(Kramdown::Document.new(
      ERB.new(#{template.source.inspect}).result(binding)
    ).to_html.html_safe)
  end
end

ActionView::Template.register_template_handler :emd, MarkdownHandler
ActionView::Template.register_template_handler :md, MarkdownHandler

但是,如果我只删除继承,那么服务器就会正常运行,并且所有markdown文件都会按预期呈现。

关于出了什么问题的任何想法?

0 个答案:

没有答案