views:

33

answers:

1

I want to delete my task ajax-style if some conditions are met. I do that with the help of link_to_remote. The thing is that link_to_remote wants to render a template and i dont want it to.

In my view ( _task_sth.html.erb):

<%= link_to_remote "Delete task", :url => {:controller => 'tasks', :action => 'delete_task', :task_pers_id => sorted_user_task.id}, :complete => "$('#{delete_task_domid}').hide();" %>

In my controller (tasks_controller.rb):

def delete_task
  task_pers = TaskPersonalization.find(params[:task_pers_id])
  horse_task = task_pers.task
  task_pers.destroy
  if horse_task.task_personalizations.empty?
    horse_task.destroy
  end
end

The task gets deleted but i get an error saying: Missing template tasks/delete_task.erb in view path app/views.

How can i make it not search for a template? I tried with adding :method => :delete at the end of link_to_remote and changing my action name to destroy. I also added render :nothing => true. I also played with routes a bit. But still i allways get the same error.

The question is how can i make it not search for a template because i dont want it to render anything?

Would be very gratefull for any answers, Roq.

+3  A: 

Have you got the same error when adding render :nothing => true? That's strange.

Rails is trying to search for a template because there's no render in your action. So to avoid it, you need to explicitly call the method:

def delete_task
  task_pers = TaskPersonalization.find(params[:task_pers_id])
  horse_task = task_pers.task
  task_pers.destroy
  if horse_task.task_personalizations.empty?
    horse_task.destroy
  end
  render :nothing => true, :status => 200
end
neutrino
thank you so much! It works now!
necker