Question

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?

Was it helpful?

Solution

Yes, you can add custom inflection rules in the file config/initializers/inflections.rb. There are examples in that file's comments.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top