我有一个配置文件模型,并有一个用户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