我创建了一个与阶段脚手架有多对一关联的项目脚手架,现在我创建了一个与阶段脚手架有多对一关联的任务脚手架。但是我的任务表没有显示,我得到了错误。errorroute.rb
resources :projects do
resources :stages do
resources :tasks
end
end
task form.html.erb
<%= form_with(model: task, url: [@stages, task], local: true) do |form| %>
<% if task.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(task.errors.count, "error") %> prohibited this task from being saved:</h2>
<ul>
<% task.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field columns large-6">
<%= form.label :task_name %>
<%= form.text_field :task_name %>
</div>
<div class="actions">
<%= form.submit 'Create', :class=>'button primary small' %>
</div>
<% end %>
Rails在您的应用程序中找不到task_path,因为您将任务移至projects
和stages
资源下,所以task_path的完整路径看起来像projects_stages_tasks_path
因此,您需要为给定的项目和阶段指定此URL
<%= form_with(model: task, url: projects_stages_tasks_path(@stages, @stages.project), local: true) do |form| %>