Note that there are some explanatory texts on larger screens.

plurals
  1. PODelete nested object
    primarykey
    data
    text
    <p>Hi im struggling with adding a link to delete an object thats nested. I have list application that has many tasks nested like this.</p> <pre><code>resources :lists do resource :tasks end </code></pre> <p>I have read this <a href="https://stackoverflow.com/questions/5710642/deleting-nested-objects-rails">post</a> but it does not work for me. I want a link to delete in this code below</p> <pre><code> &lt;h4&gt;Tasks&lt;/h4&gt; &lt;% @list.tasks.each do |task| %&gt; &lt;%= task.desc %&gt; &lt;%= link_to "Delete", list_task_path(list, task), :method =&gt; :delete %&gt;&lt;br /&gt; &lt;% end %&gt; </code></pre> <p>But it gives me the following error</p> <pre><code>undefined local variable or method `list' for #&lt;#&lt;Class:0x007f9adc555db0&gt;:0x007f9adc547828&gt; </code></pre> <p>EDIT: Now i get the following error when i refreshed the page</p> <pre><code>No route matches {:action=&gt;"show", :controller=&gt;"tasks", :list_id=&gt;#&lt;List id: 28, name: "Julklappar", user_id: 1, created_at: "2012-12-22 17:40:05", updated_at: "2012-12-22 17:40:05"&gt;, :id=&gt;#&lt;Task id: nil, desc: nil, completed: false, list_id: 28, created_at: nil, updated_at: nil&gt;} </code></pre> <p>Rake routes: </p> <pre><code>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 </code></pre> <p>Edit #2 This is my lists/show.html.erb file</p> <pre><code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt; &lt;h2&gt;&lt;%= @list.name %&gt;&lt;/h2&gt; &lt;h4&gt;Tasks&lt;/h4&gt; &lt;% @list.tasks.each do |task| %&gt; &lt;%= task.desc %&gt; &lt;%= link_to "Delete", list_task_path(@list, task), :method =&gt; :delete %&gt; &lt;% end %&gt; &lt;%= form_for [@list, @task] do |form| %&gt; &lt;p&gt;&lt;%= form.text_field :desc %&gt; &lt;%= form.submit %&gt;&lt;/p&gt; &lt;% end %&gt; &lt;%= link_to 'Edit', edit_list_path(@list) %&gt; | &lt;%= link_to 'Back', lists_path %&gt; </code></pre> <p>lists controller</p> <pre><code> def show @list = current_user.lists.find(params[:id]) @task = @list.tasks.new end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload