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

标签 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 上的说明但它没有帮助。

最佳答案

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

关于ruby-on-rails - Rails & Redcarpet:在 ApplicationHelper 中使用时未初始化的常量 Redcarpet::Render,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14670184/

相关文章:

ruby-on-rails - 无法在 Ubuntu 13.04 上使用 RVM 安装 Ruby on Rails

ruby-on-rails - RSpec 套件性能差异

ruby - 使用参数的默认值显式调用 Ruby 方法

ruby-on-rails - Rails 3.1 引擎的 Assets

jquery - 嵌套模型表单 - Railscast #196 修订 - 通过 jQuery 添加字段不起作用

ruby-on-rails - rails excel mime-type - 如何更改默认文件名?

ruby-on-rails - rails : Paypal configuration file and figaro environment variables

ruby-on-rails - Rails 新建与创建

ruby-on-rails - Bundler 似乎无法通过 Rbenv 找到正确的 Ruby

ruby-on-rails - Rails、OpenID 和 Authlogic