Boris SB
Boris SB

Reputation: 43

Application_helper and ruby gem Redcarpet error

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:

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]

Upvotes: 0

Views: 280

Answers (2)

Boris SB
Boris SB

Reputation: 43

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....

Upvotes: 0

Chetan Mehta
Chetan Mehta

Reputation: 349

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

Upvotes: 0

Related Questions