所以我整晚都在努力解决这个问题.....我基本上都设置了我的资源:
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|
但是这给了我同样的错误。
任何想法?我用谷歌搜索,我读过文章,阅读谈话..... 必须简单
答案 0 :(得分:0)
看起来你的项目是零。你需要先拥有一个项目。你的控制器是什么样的? @project是否已填充?
编辑:澄清,很可能是您的类别&gt;新方法是控制器中相关的方法。
答案 1 :(得分:0)
尝试从函数中取出空间:form_for(
...当方法中存在空格并打开parens时,Ruby经常会失败