使用本教程
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
最佳答案
好的,对于其他人来说,如果他们会像我一样陷入这种愚蠢的事情,请不要忘记在应用程序/模型中包含 category.rb ..
class Category < ActiveRecord::Base
...
end
关于ruby-on-rails - 未初始化的常量 ActionView::CompiledTemplates::Category,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10588749/