i created a project scaffold that has many to one association with stage scaffold now i created a task scaffold that has many to one association with stage scffold.
but i task form is not rendered i am getting error.
routes.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 %>
model project.rb
has_many :stages
model stage.rb
belongs_to :project
has_many :tasks
model task.rb
belongs_to :stage
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…