【问题标题】:Uninitialized Constant in Rails 3.0.1 using the RedCloth 4.2.2 gemRails 3.0.1 中使用 RedCloth 4.2.2 gem 的未初始化常量
【发布时间】:2011-06-11 22:55:30
【问题描述】:

我在本地应用程序中使用 RedCloth 时遇到问题。我不断收到以下错误:

uninitialized constant ActionView::CompiledTemplates::RedCloth

发生这种情况是因为我有以下代码:

<%= RedCloth.new("Some text").to_html %>

我试图做的是把它放在 environment.rb 文件中:

require "RedCloth"

但是,当我这样做时,我的 Phusion Passenger + Nginx 配置出现了巨大错误,我在以下论坛中对此进行了详细说明:http://railsforum.com/viewtopic.php?id=42560

任何帮助都会很棒。谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 gem initialization redcloth


    【解决方案1】:

    确保您的 Gemfile 中包含 gem 'RedCloth'。无论系统中实际安装了哪些 gem,Rails 都只会使用 Gemfile 中列出的 gem。您也不需要require "RedCloth" 语句。

    【讨论】:

    • 哇...我不敢相信这是我的问题。感谢您的帮助,希望没有其他人遇到这种情况......现在我感觉自己像新手。
    • +1 我今天遇到了同样的问题。部分原因是我是新手,部分原因是说明中没有任何内容告诉我们将其包含在 gemfile 中。 :-/
    • @jyoseph:通常,您总是需要在Gemfile 中列出您使用的任何宝石——这不仅仅是 RedCloth 的东西。
    【解决方案2】:

    我遇到了完全相同的错误,并且 Gemfile 中存在 gem 'RedCloth' 行。有什么帮助是在控制器文件的开头添加 require 语句

    require 'redcloth'
    
    class StaticController < ApplicationController
    ...
    

    【讨论】:

    • 这对我有用(虽然我需要'RedCloth'而不是'redcloth')。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多