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

sun*_*eja 6 ruby ruby-on-rails railscasts redcarpet

我正在关注语法高亮修订的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
Run Code Online (Sandbox Code Playgroud)

但是,我的网络应用程序返回

Routing Error

uninitialized constant Redcarpet::Render

Try running rake routes for more information on available routes. 
Run Code Online (Sandbox Code Playgroud)

我正在使用Rails 3.2.11并且Redcarpet在rails控制台中做出了很好的响应.我原本没有包括,require 'redcarpet'但我按照这里的说明,但它没有帮助.

sun*_*eja 7

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

  • 顺便说一下,您可能只是需要重新启动服务器.这就是我的情况. (17认同)