2010-09-20 51 views
1

我在構建我認爲是一個相當簡單的食譜應用程序,同時學習RoR。導軌鏈接表「未初始化的常量」錯誤

我已經爲用戶提供了一個表格,還有一個食譜表格,以及一個recipe_users表格,用戶正在保存食譜列表。

我從軌得到的錯誤是「未初始化的常數用戶:: RecipeUser」

我的型號如下

 
class User < ActiveRecord::Base 
    acts_as_authentic 

    has_many :recipe_users 
    has_many :recipes, :through = > :recipe_users 
end 

class Recipes < ActiveRecord::Base 
    has_many :ingredients, :dependent => :destroy 
    has_many :recipe_users 
    has_many :users, :through => :recipe_users 
end 

class RecipeUsers < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :recipe 
end 
現在

在我的用戶控制,我試圖打電話

 
@user = User.find(current_user.id) 
@userRecipes = @user.recipes.find() 

看着我的mysql顯示錶,我得到

 
recipe_users 
recipes 
schema_migrations 
user_sessions 
users 

就我所知,我的命名約定是正確的。

任何建議,爲什麼我得到這個錯誤?

回答

1

看起來這是一個命名約定的問題。

我刪除了所有對recipe_users的引用,並將餐桌,模型和控制器重新創建爲膳食。

不是一個很好的名字,但它都彙集在一起​​。

我從來不喜歡Rails似乎期望的命名約定,我認爲部分原因是由於複數化而沒有實際通知開發人員可能期望的名稱。

相關問題