【问题标题】:uninitialized constant ActionView::CompiledTemplates::Category未初始化的常量 ActionView::CompiledTemplates::Category
【发布时间】:2012-05-14 18:11:38
【问题描述】:

使用本教程

http://railscasts.com/episodes/57-create-model-through-text-field

需要让它在我的应用程序中运行,在 rails 3.0.7 上运行良好,将其更新到 3.1.3,我现在收到此错误

uninitialized constant ActionView::CompiledTemplates::Category

我会花更多时间寻找答案,但现在我的时间真的很短。我已经查看了与此问题相关的大部分谷歌结果,但没有任何好处。需要帮助。

表格

<%= f.collection_select :category_id, Category.find(:all), :id, :name, :prompt => "Select a Category" %>
or create one:
<%= f.text_field :new_category_name %>

型号

class Tvstation < ActiveRecord::Base
  belongs_to :category
  attr_accessor :new_category_name
  before_save :create_category_from_name

  def create_category_from_name
    create_category(:name => new_category_name) unless new_category_name.blank?
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1


    【解决方案1】:

    好的,如果他们会像我一样陷入这种愚蠢的事情,别忘了在 app/models 中包含 category.rb..

    class Category < ActiveRecord::Base
      ...
    end
    

    【讨论】:

      【解决方案2】:

      对我来说,我在视图中遇到了类似的问题。我的类别模型在命名空间示例中可用

      模块金融 类别 类别 结尾 结尾

      当我简单地调用 Category.get_method 时。它给出了同样的错误。所以我修改为 Financial::Category 解决了我的问题。

      【讨论】:

        【解决方案3】:

        我使用的是 PORO,但它没有加载,给我这个错误。那是因为我改了类名,没有改文件名。

        【讨论】:

          【解决方案4】:

          其他人如何建议我通过修复错误的型号名称解决了类似的问题。

          【讨论】:

            猜你喜欢
            • 2012-04-29
            • 2023-03-04
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-03-02
            • 1970-01-01
            • 1970-01-01
            • 2015-12-29
            相关资源
            最近更新 更多