开发者

rails can`t pluralize word 'affiche'

开发者 https://www.devze.com 2023-04-12 20:58 出处:网络
I have a model called affiche and model user cl开发者_如何转开发ass User < ActiveRecord::Base

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号