Rails& Redcarpet:在ApplicationHelper中使用时未初始化的常量Redcarpet :: Render

时间:2013-02-03 06:55:30

标签: ruby-on-rails ruby railscasts redcarpet

我正在关注Syntax Highlighting Revised的RailsCasts剧集。我将ApplicationHelper更新为:

require 'redcarpet'

module ApplicationHelper
  class HTMLwithPygments < Redcarpet::Render::HTML
    def block_code(code, language)
      Pygments.highlight(code, lexer:language)
    end
  end

  def markdown(text)
    renderer = HTMLwithPygments.new(hard_wrap: true, filter_html: true)
    options = {
      autolink: true,
      no_intra_emphasis: true,
      fenced_code_blocks: true,
      lax_html_blocks: true,
      strikethrough: true,
      superscript: true
    }
    Redcarpet::Markdown.new(renderer, options).render(text).html_safe
  end
end

但是,我的网络应用返回

Routing Error

uninitialized constant Redcarpet::Render

Try running rake routes for more information on available routes. 

我正在使用Rails 3.2.11,Redcarpet在rails控制台中响应很好。我最初没有包含require 'redcarpet',但我按照here上的说明操作,但没有帮助。

1 个答案:

答案 0 :(得分:7)

我删除了Gemfile.lock并再次bundle install,但效果非常好。