rails can`t pluralize word 'affiche'
I have a model called affiche
and model user
cl开发者_如何转开发ass 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?
Yes, you can add custom inflection rules in the file config/initializers/inflections.rb
. There are examples in that file's comments.
You can specify the class name of the children as an option to has_many
. Something like:
class User < ActiveRecord::Base
has_many :affiches, class_name: 'Affiche'
end
See http://apidock.com/rails/v4.0.2/ActiveRecord/Associations/ClassMethods/has_many for further examples.
精彩评论