Ruby on rails Rails认为;“faves”;是指名为“的模型”;Fafe“;
我有一个名为Ruby on rails Rails认为;“faves”;是指名为“的模型”;Fafe“;,ruby-on-rails,naming-conventions,camelcasing,Ruby On Rails,Naming Conventions,Camelcasing,我有一个名为Fave的模型。它属于另一个名为User的模型 我试图通过调用@User.Faves来查找用户的最爱。我的服务器返回以下错误: NameError: uninitialized constant User::Fafe 为什么它会认为“faves”的单数是“fafe”?是否有其他复数形式可以指向“fave”?我们可以在config/initializers/definctions.rb中尝试一下吗?这可能行得通 ActiveSupport::Inflector.inflections
Fave
的模型。它属于另一个名为User
的模型
我试图通过调用@User.Faves
来查找用户的最爱。我的服务器返回以下错误:
NameError: uninitialized constant User::Fafe
为什么它会认为“faves”的单数是“fafe”?是否有其他复数形式可以指向“fave”?我们可以在
config/initializers/definctions.rb中尝试一下吗?这可能行得通
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'fave', 'faves' #append this to the existing ones
end
我们可以在config/initializers/definctions.rb
中试试吗?这可能行得通
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'fave', 'faves' #append this to the existing ones
end
您可以在设置关联时传递类名
has_many :faves, class_name: "Fave"
您可以在设置关联时传递类名
has_many :faves, class_name: "Fave"
这似乎是可能的。我知道Rails查找“sleeve”复数屈折变化所依赖的regexp将返回“sleefe”而不是“Sleets”。请查看有关屈折变化在Rails中如何工作的更多详细信息。这似乎是可能的。我知道Rails查找“sleeve”复数屈折变化所依赖的regexp将返回“sleefe”而不是“Sleets”。请查看有关屈折变化在Rails中如何工作的更多详细信息。