0

所以我整晚都在努力解决这个问题......我基本上已经将我的资源设置为:

resources :projects do
   resources :categories
end

在我的部分形式中,我有:

<%= form_for ([@project, @category]) do |f| %>
<% end %>

它给了我错误:

No route matches {:controller=>"categories", :format=>nil, :project_id=>#<Project id: nil, project_title: nil, user_id: nil, created_at: nil, updated_at: nil>}

Try running rake routes for more information on available routes. 

我的类别路线如何:

     project_categories GET    /projects/:project_id/categories(.:format)           categories#index
                        POST   /projects/:project_id/categories(.:format)           categories#create
   new_project_category GET    /projects/:project_id/categories/new(.:format)       categories#new
  edit_project_category GET    /projects/:project_id/categories/:id/edit(.:format)  categories#edit
       project_category GET    /projects/:project_id/categories/:id(.:format)       categories#show
                        PUT    /projects/:project_id/categories/:id(.:format)       categories#update
                        DELETE /projects/:project_id/categories/:id(.:format)       categories#destroy

发生了什么事,为什么这不起作用。我已经尝试了一切,我尝试将项目变量传递到渲染路径然后执行:(给我一个差异错误,抱怨类别未定义)

form_for project.categories.build do |f|

我什至尝试过

form_for ([project, project.categories.build]) do |f|

但这给了我与上面相同的错误。

有任何想法吗?我用谷歌搜索过,我读过文章,读过演讲......它一定很简单

4

2 回答 2

0

看起来你的项目是零。你需要先有一个项目。你的控制器是什么样的?@project 是否已填充?

编辑:澄清一下,您的 Categories > New 方法很可能是控制器中相关的方法。

于 2012-09-08T04:07:29.320 回答
0

尝试从函数中取出空格:form_for(...当方法中存在空格并打开括号时,Ruby 通常会失败

于 2012-09-08T04:07:49.633 回答