Rails 3 Gemfile Gems not loading after package installation

I am writing an application in Rails 3 with Ruby v2.0.0.

I have an assistant in app / helpers / posts_helper.rb:

module PostsHelper def markdown(text) @redcarpet = Redcarpet::Markdown.new(Redcarpet::Render::HTML, {fenced_code_blocks: true}) unless @redcarpet @redcarpet.render text end end 

My Gemfile contains the gem 'redcarpet', '~> 2.2' , and I successfully completed the bundle install . However, I get this error whenever I try to load a page using this helper:

 uninitialized constant PostsHelper::Redcarpet 

What can I do to make this work? I am puzzled by this problem.

Edit:

I also tested Redcarpet in the rails console :

 $ bundle exec rails console Loading development environment (Rails 3.2.13) irb(main):001:0> Redcarpet::Markdown.new(Redcarpet::Render::HTML).render('text *markdownified*') => "<p>text <em>markdownified</em></p>\n" 

Therefore, it works in the console, just not in my assistant (or controller, I tried this too).

+4
source share
1 answer

Ruby is trying to find Redcarpet in the PostsHelper namespace. Use ::Redcarpet to take it to the global namespace

+2
source

Source: https://habr.com/ru/post/1480306/


All Articles