Ruby-on-rails 未初始化的常量 ActionView::CompiledTemplates::Category
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10588749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
uninitialized constant ActionView::CompiledTemplates::Category
提问by rmagnum2002
using this tutorial
使用本教程
http://railscasts.com/episodes/57-create-model-through-text-field
http://railscasts.com/episodes/57-create-model-through-text-field
need to make it work in my app, was on rails 3.0.7 and it worked fine, updated it to 3.1.3 and I got this error now
需要让它在我的应用程序中运行,在 Rails 3.0.7 上运行良好,将其更新为 3.1.3,我现在收到此错误
uninitialized constant ActionView::CompiledTemplates::Category
I would look for answers more time but now I am really short on time. I have looked into most part of google results related to this problem and no good. Need help please.
我会花更多时间寻找答案,但现在我真的没时间了。我已经查看了与此问题相关的大部分谷歌结果,但没有任何好处。需要帮助请。
form
形式
<%= f.collection_select :category_id, Category.find(:all), :id, :name, :prompt => "Select a Category" %>
or create one:
<%= f.text_field :new_category_name %>
model
模型
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
回答by rmagnum2002
ok, just for others if they will get into this stupid things as I did, don't forget to have the category.rb in the app/models..
好的,对于其他人来说,如果他们会像我一样陷入这种愚蠢的事情,请不要忘记在应用程序/模型中包含 category.rb ..
class Category < ActiveRecord::Base
...
end
回答by Madhan Ayyasamy
For me, i got the similar problem in the views. My Category model is available inside namespace example
对我来说,我在视图中遇到了类似的问题。我的类别模型在命名空间示例中可用
Module Financial class Category end end
When i call simply Category.get_method. It was giving same error. so that i modified into Financial::Categorythat solved my problem.
当我简单地调用 Category.get_method 时。它给出了同样的错误。所以我修改为Financial::Category解决了我的问题。
回答by ryan2johnson9
I was using a PORO and it wasn't loading, giving me this error. It was because I had changed the class name without changing the file name.
我正在使用 PORO 但它没有加载,给我这个错误。那是因为我在没有改变文件名的情况下改变了类名。
回答by Wellington1993
How the others suggested I had a similar problem solved be fix of wrong model name.
其他人如何建议我解决了类似的问题是修复了错误的模型名称。

