0
我有一個名爲Fave
的模型。它屬於另一個名爲User
的模型。Rails認爲「faves」是指名爲「Fafe」的模型
我試圖通過致電@user.faves
找到用戶的收藏。我的服務器給我回來了以下錯誤:
NameError: uninitialized constant User::Fafe
爲什麼它會認爲「faves」的單數是「fafe」?有什麼其他複數形式我可以使用,將指向「fave」?
我有一個名爲Fave
的模型。它屬於另一個名爲User
的模型。Rails認爲「faves」是指名爲「Fafe」的模型
我試圖通過致電@user.faves
找到用戶的收藏。我的服務器給我回來了以下錯誤:
NameError: uninitialized constant User::Fafe
爲什麼它會認爲「faves」的單數是「fafe」?有什麼其他複數形式我可以使用,將指向「fave」?
而設立的關聯
has_many :faves, class_name: "Fave"
我們可以在config/initializers/inflections.rb
試試嗎?這可能是工作
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'fave', 'faves' #append this to the existing ones
end
這可能似乎可以把類名。我知道Rails依賴於找到「袖子」的複數變形的正則表達式將返回「sleefe」而不是「袖子」。看看[這個答案](http://stackoverflow.com/questions/32337665/table-pluralization/32337815#32337815)瞭解更多關於在Rails中如何工作的細節。 – MarsAtomic