未初始化的常量ActionView :: CompiledTemplates :: Category

rma*_*002 9 ruby-on-rails ruby-on-rails-3.1

使用本教程

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

需要让它在我的应用程序中工作,在rails 3.0.7上工作正常,更新到3.1.3我现在收到此错误

uninitialized constant ActionView::CompiledTemplates::Category
Run Code Online (Sandbox Code Playgroud)

我会寻找更多时间的答案,但现在我的时间非常短.我已经调查了与此问题相关的谷歌搜索结果的大部分内容并没有什么好处.需要帮助.

形成

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

模型

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
Run Code Online (Sandbox Code Playgroud)

rma*_*002 26

好的,只是对于其他人,如果他们会像我一样进入这个愚蠢的事情,不要忘记在app/models中有category.rb ..

class Category < ActiveRecord::Base
  ...
end
Run Code Online (Sandbox Code Playgroud)