Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9115133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:21:30+00:00 2026-06-17T04:21:30+00:00

Hi im struggling with adding a link to delete an object thats nested. I

  • 0

Hi im struggling with adding a link to delete an object thats nested. I have list application that has many tasks nested like this.

resources :lists do
  resource :tasks
end

I have read this post but it does not work for me. I want a link to delete in this code below

    <h4>Tasks</h4>
<% @list.tasks.each do |task| %>
    <%= task.desc %>
    <%= link_to "Delete", list_task_path(list, task), :method => :delete %><br />
<% end %>

But it gives me the following error

undefined local variable or method `list' for #<#<Class:0x007f9adc555db0>:0x007f9adc547828>

EDIT: Now i get the following error when i refreshed the page

No route matches {:action=>"show", :controller=>"tasks", :list_id=>#<List id: 28, name: "Julklappar", user_id: 1, created_at: "2012-12-22 17:40:05", updated_at: "2012-12-22 17:40:05">, :id=>#<Task id: nil, desc: nil, completed: false, list_id: 28, created_at: nil, updated_at: nil>}

Rake routes:

pierre@ubuntu:~/todolist$ rake routes
              list_tasks GET    /lists/:list_id/tasks(.:format)          tasks#index
                         POST   /lists/:list_id/tasks(.:format)          tasks#create
           new_list_task GET    /lists/:list_id/tasks/new(.:format)      tasks#new
          edit_list_task GET    /lists/:list_id/tasks/:id/edit(.:format) tasks#edit
               list_task GET    /lists/:list_id/tasks/:id(.:format)      tasks#show
                         PUT    /lists/:list_id/tasks/:id(.:format)      tasks#update
                         DELETE /lists/:list_id/tasks/:id(.:format)      tasks#destroy
                   lists GET    /lists(.:format)                         lists#index
                         POST   /lists(.:format)                         lists#create
                new_list GET    /lists/new(.:format)                     lists#new
               edit_list GET    /lists/:id/edit(.:format)                lists#edit
                    list GET    /lists/:id(.:format)                     lists#show
                         PUT    /lists/:id(.:format)                     lists#update
                         DELETE /lists/:id(.:format)                     lists#destroy
        new_user_session GET    /users/sign_in(.:format)                 devise/sessions#new
            user_session POST   /users/sign_in(.:format)                 devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                devise/sessions#destroy
           user_password POST   /users/password(.:format)                devise/passwords#create
       new_user_password GET    /users/password/new(.:format)            devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)           devise/passwords#edit
                         PUT    /users/password(.:format)                devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                  devise/registrations#cancel
       user_registration POST   /users(.:format)                         devise/registrations#create
   new_user_registration GET    /users/register(.:format)                devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                    devise/registrations#edit
                         PUT    /users(.:format)                         devise/registrations#update
                         DELETE /users(.:format)                         devise/registrations#destroy
                    root        /                                        lists#index

Edit #2
This is my lists/show.html.erb file

<p id="notice"><%= notice %></p>

<h2><%= @list.name %></h2>

    <h4>Tasks</h4>
    <% @list.tasks.each do |task| %>
        <%= task.desc %>
        <%= link_to "Delete", list_task_path(@list, task), :method => :delete %>
    <% end %>

<%= form_for [@list, @task] do |form| %>

    <p><%= form.text_field :desc %> <%= form.submit %></p>

<% end %>

<%= link_to 'Edit', edit_list_path(@list) %> |
<%= link_to 'Back', lists_path %>

lists controller

  def show
    @list = current_user.lists.find(params[:id])
    @task = @list.tasks.new
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:21:31+00:00Added an answer on June 17, 2026 at 4:21 am

    Your link should be:

    <%= link_to "Delete", list_task_path(@list, task), :method => :delete %>
    

    When looping through @list.tasks, you are only localizing task through |task| – but @list always stays @list.

    The other problem is in your controller: @task = @list.tasks.new – your building a new task here, which is needed for your form. However, this task is new, which means it hasn’t been saved yet – you simply cannot build a link to delete it, because it doesn’t exist in the database yet. You can avoid this by building the task directly in the form, not in the controller.

    Get rid of this line in the controller:

    @task = @list.tasks.new
    

    And change your form to:

    <%= form_for [@list, @list.tasks.build] do |form| %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling on doing a simple thing, I have an object that generates a
Im struggling with this one. I have a list of items and on a
I'm adding a categorization functionality to my app and struggling with it. Objects have
I'm struggling with adding a map scale that displays current length on screen depending
I have the following query that I would like to convert to LINQ to
I am struggling to figure if whether adding an already existing object to a
I have been struggling to hide another application from the taskbar from my application.
I'm adding new features to a legacy application written in PHP that uses an
Struggling to get any list function to work. I've been fine with _show and
Struggling with a bit of a mystery regarding a ghost like JESSIONID Cookie. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.