Ruby on rails 表多元化?

Ruby on rails 表多元化?,ruby-on-rails,ruby-on-rails-4,rails-activerecord,Ruby On Rails,Ruby On Rails 4,Rails Activerecord,我有3个具有以下关系的表(为了简单明了,对表进行了修剪): 我的模特是这样的: class User < ActiveRecord::Base has_many :sleeves end class Sleeve < ActiveRecord::Base belongs_to :user has_many :reports end class Report < ActiveRecord::Base belongs_to :sleeve end Active

我有3个具有以下关系的表(为了简单明了,对表进行了修剪):

我的模特是这样的:

class User < ActiveRecord::Base
  has_many :sleeves
end

class Sleeve < ActiveRecord::Base
  belongs_to :user
  has_many :reports
end

class Report < ActiveRecord::Base
  belongs_to :sleeve
end
ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'sleeve', 'sleeves'
end
我得到以下错误:

NameError: uninitialized constant User::Sleefe
from "../gems/ruby-2.2.2/gems/activemodel-4.2.3/lib/active_record/inheritance.rb:158:in 'compute_type'
如果我将模型中的用户关系更改为:

class User < ActiveRecord::Base
  has_one :sleeve
end
class用户
一切正常(但我只收到一份报告,而不是我需要的所有报告)。我怀疑问题在于单词Sleeve的多重化(正如错误所说的Sleefe——代码中没有)

有人能给我指出正确的纠正方法吗?

在Rails中,复数形式被称为“”,它们是为您预定义的

为了加深理解,Rails使用了一组正则表达式来根据单词的结尾确定正确的复数形式。(您可以在
您的应用程序/lib/active\u支持/屈折变化.rb
中看到它们)。正则表达式是匹配模式的有效方法,但它们取决于目标材质中的一致性。英语,作为一种自然语言,是不规则和不一致的,这就是像“sleefe”这样的问题产生的原因

在您的情况下,您希望通过对拐点文件执行一些小操作来覆盖看起来不正确的拐点

开放式:

编辑拐点.rb,使其看起来像这样:

class User < ActiveRecord::Base
  has_many :sleeves
end

class Sleeve < ActiveRecord::Base
  belongs_to :user
  has_many :reports
end

class Report < ActiveRecord::Base
  belongs_to :sleeve
end
ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'sleeve', 'sleeves'
end
ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'sleeve', 'sleeves'
end