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