所以我有项目与类别的关系,这样一个项目可以有很多类别,一个类别属于一个项目。我已经设法让它工作了,但是现在 - 当我重新启动我的 rails 服务器时,它不起作用。我在下面显示的代码是我在重新启动之前和重新启动我的 rails 服务器之后所拥有的,所以我认为它与代码有关......
所以我不确定你是否需要模型或只是控制器或表单或什么,所以我已经从类别控制器发布了 create 方法,因为这就是问题发生的地方:
def create
@project = Project.find(params[:project_id])
@category = @project.categories.create(params[:category].merge(:user_id => current_user.id))
if @category.save
redirect_to project_tasks_path(@project.id), :flash => {:success => 'Created a Category! Now you can create tasks!'}
else
redirect_to :back, :flash => {:error => 'We could not create an category. You need to enter a name.'}
end
end
它发生在心理创建线上,引发错误:
RuntimeError in CategoriesController#create
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
Rails.root: /home/adam/Documents/Aptana Studio 3 Workspace/StartPoint
Application Trace | Framework Trace | Full Trace
app/controllers/categories_controller.rb:14:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"qbJyilRiMtwOyPDq9HQFO4JME+TPkh/cCEEqPZPxGDw=",
"category"=>{"category"=>"ffffffff"},
"commit"=>"Create Category",
"project_id"=>"2"}
这是在点击创建时抛出的。有什么想法还是我需要显示更多代码?