2014-01-10 22 views
0

我正在学习嵌套资源,并在尝试编辑事件时遇到以下错误。事件资源嵌套在用户资源下。有小费吗?如何编辑涉及嵌套资源的位置?

 ActiveRecord::RecordNotFound: 
     Couldn't find Event with id=133 [WHERE "user_events"."user_id" = $1] 
    # ./app/controllers/events_controller.rb:32:in `edit' 
    # ./spec/features/user_edits_reg_info.rb:69:in `block (2 levels) in <top (required)>' 

活动控制器

def edit 
    @event = current_user.events.find(params[:id]) 
    end 

回答

0

这听起来像Event与ID = 133不属于current_user,但不同的用户。

假设你在类似/users/1/events/133/edit的URL访问这个,你应该找到一个从:user_id参数(1在我的例子)的用户,而不是使用current_user

def edit 
    @user = User.find(params[:user_id]) 
    @event = @user.events.find(params[:id]) 
end 
+0

这也不能工作。当我运行我的测试创建事件时,他们正确地关联,我希望这意味着它是真实的。 – John