我有两个模特:
员额:
class Post < ActiveRecord::Base
has_many :exes
end主管:
class Exe < ActiveRecord::Base
belongs_to :post
end我对http://localhost:3000/posts/index的看法是:
NameError in Posts#index
uninitialized constant Post::Ex上面写着Ex是有原因的。
鲁比抱怨的代码是<% post.exes.each do |exe| %>,这在我看来是对的。
所以我真的不知道为什么会这样。如果我也检查了以下内容,我认为这可能是原因,但不是:
2.0.0-p247 :004 > ActiveSupport::Inflector.pluralize('Exe')
=> "Exes"
2.0.0-p247 :005 > ActiveSupport::Inflector.singularize('Exe')
=> "Exe" 提前感谢!
发布于 2013-09-12 00:09:49
您的问题是ActiveSupport::Inflector假设以复数形式以'xes‘结尾的单词必须以'x’以单数形式结尾。有关自定义多元化的帮助,请参见See here。
更新:,不知怎么的,我错过了你问题的最后一部分。你说你试过了
> ActiveSupport::Inflector.singularize('Exe')但你试过:
> ActiveSupport::Inflector.singularize('Exes')https://stackoverflow.com/questions/18753277
复制相似问题