Rails 不能将单词“affiche”复数化;
我有一个名为 affiche
的模型和一个名为 user
的模型
class User < ActiveRecord::Base
has_many :affiches
class Affiche < ActiveRecord::Base
belongs_to :user
,尝试从数据库获取时出现错误:
uninitialized constant User::Affich
如果它没有删除 e
> 我想,如果有信的话那就太好了。
有什么方法可以告诉rails不知道的单词如何复数吗?
I have a model called affiche
and model user
class User < ActiveRecord::Base
has_many :affiches
class Affiche < ActiveRecord::Base
belongs_to :user
And there i get an error, trying to fetch from db:
uninitialized constant User::Affich
if it didn`t erased the e
letter it would be nice, i think.
Is there any way to tell how to pluralize words rails doesn`t know about?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以在文件
config/initializers/inflections.rb
中添加自定义变形规则。该文件的注释中有示例。Yes, you can add custom inflection rules in the file
config/initializers/inflections.rb
. There are examples in that file's comments.您可以将子级的类名指定为
has_many
的选项。类似于:请参阅 http://apidock.com/rails/v4.0.2 /ActiveRecord/Associations/ClassMethods/has_many 了解更多示例。
You can specify the class name of the children as an option to
has_many
. Something like:See http://apidock.com/rails/v4.0.2/ActiveRecord/Associations/ClassMethods/has_many for further examples.