Rails & Redcarpet: uninitialized constant Redcarpet::Render when used in ApplicationHelper
Asked Answered
P

1

8

I'm following along the RailsCasts episode for Syntax Highlighting Revised. I updated my ApplicationHelper to look like so:

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

However, my web app returns

Routing Error

uninitialized constant Redcarpet::Render

Try running rake routes for more information on available routes. 

I'm using Rails 3.2.11 and Redcarpet responds fine in rails console. I've originally didn't include require 'redcarpet' but I followed the instructions on here but it didn't help.

Primm answered 3/2, 2013 at 6:55 Comment(0)
P
7

I removed my Gemfile.lock and did bundle install again and it worked perfectly.

Primm answered 11/2, 2013 at 20:40 Comment(3)
BTW it might just have been that you needed to restart your server. This was the case for me.Penholder
I tried that a few times and it didn't help but I'll keep the advice in mind in case of future strangeness. :)Primm
@Penholder that was the case for me, in the rails console reload! didn't do it, I had to stop and restart it.Utgardloki

© 2022 - 2024 — McMap. All rights reserved.