我有一個配置文件模型,並有一個用戶has_one配置文件。爲什麼我會得到「未定義的方法」?
這裏是我的路線:
resources :users
resources :profiles
下面是我的控制器的顯示方法:
NoMethodError in ProfilesController#show
undefined method `profile' for nil:NilClass
:
def show
@profile = @user.profile
end
爲什麼當我嘗試訪問放映視圖我得到這個錯誤
現在我得到這個錯誤:'的ActiveRecord :: RecordNotFound在ProfilesController#顯示 找不到用戶與ID = 2' – 2011-03-27 04:43:27
哈哈一模一樣的答案 – Shiv 2011-03-27 04:43:34
確定這是因爲用戶不存在,嘗試傳入一些其他的ID,它應該工作 – Shiv 2011-03-27 04:43:57