hamchapman
hamchapman

Reputation: 3361

Error when trying to inherit from ActionView::Template::Handler in Rails 3.2.13

I tried upgrading from Rails 3.0.23 to 3.2.13 and now I have an error stopping the server from starting that looks like this:

/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>'

The code that is causing this looks like:

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

However, if I just remove the inheritance then the server starts fine and all of the markdown files render as expected.

Any ideas as to what's going wrong?

Upvotes: 3

Views: 131

Answers (0)

Related Questions