I have set up a site that is correctly using basic CRUD functionality succesfully. However, when I try to add a custom method to my controller I cannot seem to hook it up to a link_to call. I keep getting a method not found error.
The Controller method looks like this:
def complete
return render :text => "Complete"
end
and my call in the View looks like this:
<%= link_to 'Complete', complete_list_task_path(@list,@task) %>
This same call works for my Edit method, so I’m not sure what I’m doing wrong. Do I need to do anything special when the method is not a basic CRUD call?
The only relevant part of my route file looks like this (List and Task are nested resources. List has many tasks, and task belongs to a list):
resources :lists do
resources :tasks
end
I have also tried adding post "complete" => "lists/:id/tasks/:id#complete", :as => "complete" to my route to see if it would help to implicitly try to call it, but I still got a “method not found error”.
Any help in figuring out how to make this call would be greatly appreciated. Thank you!
You need to declare the method in the router, ‘resources’ refers to the 7 crud actions (index, new, create, edit, update, delete, show).
Off the top of my head, I think you’d need:
The nesting makes me less confident, but that’s the general thing you need to do.