I'm writing an application in Rails 3 with Ruby v2.0.0.
I have a helper 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 gem 'redcarpet', '~> 2.2'
and I have run bundle install
with success. However, I get this error whenever I try to load a page that uses this helper:
uninitialized constant PostsHelper::Redcarpet
What can I do to get this working? I'm baffled at this problem.
Edit:
I've also tested Redcarpet in 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"
So it works in the console, just not in my helper (or controller, I've tried that, too).