我创建了一个任务模型,除了我去删除任务之外,一切正常。即使在数据库中没有任务,@ wood.tasks.length仍为1,也会发生奇怪的事情。
_task.html.erb
<%= link_to 'MARK COMPLETED', plant_task_path(@plant, task), method: :delete %>
以下是我工厂展示的代码
<div class="col-md-4">
<div class="jumbotron">
<%= render 'tasks/form' %>
<% if @plant.tasks.length != 0 %>
<%= render @plant.tasks %>
<% end %>
<%= @plant.tasks.length %>
</div>
</div>
创建任务的表单:
form_for([@plant, @plant.tasks.build])
我的路线:
resources :plants do
resources :tasks
Rake Routes:
complete_plant_task PATCH /plants/:plant_id/tasks/:id/complete(.:format) tasks#complete
plant_tasks GET /plants/:plant_id/tasks(.:format) tasks#index
POST /plants/:plant_id/tasks(.:format) tasks#create
new_plant_task GET /plants/:plant_id/tasks/new(.:format) tasks#new
edit_plant_task GET /plants/:plant_id/tasks/:id/edit(.:format) tasks#edit
plant_task GET /plants/:plant_id/tasks/:id(.:format) tasks#show
PATCH /plants/:plant_id/tasks/:id(.:format) tasks#update
PUT /plants/:plant_id/tasks/:id(.:format) tasks#update
DELETE /plants/:plant_id/tasks/:id(.:format) tasks#destroy
我的任务控制器
def create
@task = @plant.tasks.create(task_params)
redirect_to @plant
end
private
def set_plant
@plant = Plant.find(params[:plant_id])
end
def set_task
@task = @plant.tasks.find(params[:id])
end
我得到了这个我的踪迹
app/views/tasks/_task.html.erb:7:in `_app_views_tasks__task_html_erb__1645613233755040561_70222907197480'
app/views/plants/show.html.erb:82:in `_app_views_plants_show_html_erb__4438670005226416605_70222868774180'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:259:in `raise_generation_error'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:234:in `optimized_helper'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:220:in `call'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:345:in `block (2 levels) in define_url_helper'
app/views/tasks/_task.html.erb:7:in `_app_views_tasks__task_html_erb__1645613233755040561_70222907197480'
actionview (4.2.6) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.6) lib/active_support/notifications.rb:166:in `instrument'
我整晚都试图想出这个。任何人都可以帮我解决这个问题吗?非常感谢