简体   繁体   English

捆绑安装后未加载Rails 3 Gemfile Gems

[英]Rails 3 Gemfile Gems not Loading After Bundle Install

I'm writing an application in Rails 3 with Ruby v2.0.0. 我正在用Ruby v2.0.0在Rails 3中编写一个应用程序。

I have a helper in app/helpers/posts_helper.rb: 我在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. 我的Gemfile包含Gemfile gem 'redcarpet', '~> 2.2'并且我成功运行了bundle install 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 : 我也已经在rails console测试了Redcarpet:

$ 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). 因此它可以在控制台中工作,而不能在我的助手(或控制器,我也尝试过)中工作。

Ruby is trying to find Redcarpet in the PostsHelper namespace. Ruby尝试在PostsHelper命名空间中找到Redcarpet。 Use ::Redcarpet to raise that to the global namespace 使用::Redcarpet将其引发到全局名称空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM