【问题标题】:Rails & Redcarpet: uninitialized constant Redcarpet::Render when used in ApplicationHelperRails & Redcarpet:在 ApplicationHelper 中使用时未初始化的常量 Redcarpet::Render
【发布时间】:2013-02-03 06:55:29
【问题描述】:

我正在关注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 上的说明进行操作,但没有帮助。

【问题讨论】:

    标签: ruby-on-rails ruby railscasts redcarpet


    【解决方案1】:

    我删除了我的Gemfile.lock 并再次删除了bundle install,它运行良好。

    【讨论】:

    • 顺便说一句,您可能需要重新启动服务器。我就是这种情况。
    • 我尝试了几次,但没有帮助,但我会记住这些建议,以防将来出现奇怪的情况。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多