0

I am trying to get the markdown up and running on my webapp using pygment 0.6.3 and redcarpet 3.3. Unfortunately, I am facing a wall here when calling the markdown method:

uninitialized constant ApplicationHelper::Redcarpet

Here is the module I am calling from application_helper.rb:

module ApplicationHelper
    def markdown(content)
        renderer = Redcarpet::Render::HTML.new(hard_wrap: true, filter_html: true)
        options = {
            autolink: true, 
            no_intra_emphasis: true,
            disable_indented_code_blocks: true,
            fenced_code_blocks: true,
            lax_html_blocks: true,
            strikethrough: true,
            superscript: true
        }
        Redcarpet::Markdown.new(renderer, options).render(content).html_safe
    end
end

I am therefore call this method the following way:

<div id= "content">
        <%= markdown @post.content%>
</div>

Among other researches, I already did the following:

  • bundle update
  • bundle install
  • restart my server
  • tried other versions of pygments and redcarpet

I've found some info saying I should remove the Gemfile.lock (when deleting it, it automatically pops up again).

Thank you for your help on this.

Edit: Added Gemfile

source 'https://rubygems.org'

gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'sqlite3'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'pygments.rb', '~> 0.6.3'
gem 'redcarpet', '~> 3.3', '>= 3.3.4'

group :development, :test do
  gem 'byebug', platform: :mri
end

group :development do
  gem 'web-console'
  gem 'listen', '~> 3.0.5'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Boris SB
  • 43
  • 1
  • 10

2 Answers2

0

Try writing this in you file

before_save :assign_markdown_content, if: -> { content_changed? }

  def assign_markdown_content
    assign_attributes({
      markdown_content: self.class.markdown.render(content)
    })
  end
Chetan Mehta
  • 349
  • 3
  • 12
  • thanks for this. I am not quite sure where to put this piece of code tho. Can you elaborate? – Boris SB Nov 26 '16 at 09:51
  • Also, after revising my code for the past 24h hours, it seemedI had a small spelling mistake between in my variable "render"... I edited my post accordingly. Nevertheless, this error happened to me before. For some magical reason, it works now. Unbelievably frustrating not to be able to understand why it's up and running this time, but I am buying it! – Boris SB Nov 26 '16 at 09:54
0

For all those who might encounter this problem, even with other functionalities you want to implement, hit the CTRL-C command, shut down your rails server, do not only bundle install and rails s.

After an entire day of trying to understand what was going on under the hood, the CTRL-C felt like Xmas....

Boris SB
  • 43
  • 1
  • 10