首页 文章

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

提问于
浏览
6

我正在关注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.

我'm using Rails 3.2.11 and Redcarpet responds fine in rails console. I' ve最初没有包含 require 'redcarpet' 但是我按照here上的说明进行了操作,但它没有帮助 .

1 回答

  • 7

    我删除了我的 Gemfile.lock 并再次做了 bundle install ,它完美无缺 .

相关问题