ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Rolling with Ruby on Rails, Part 2
Subject:   Custom Delete Method Not Needed
Date:   2005-10-14 21:53:20
From:   dkeo
In part 1 of this article your wrote:
"A single line of code, scaffold :recipe, brought everything to life...With virtually no work on our part, it created the actions list, show, edit, and delete."
And further:
"we can leave the scaffolding in place and slowly, one at a time, provide our own versions of the actions and views. Each time you create one of the actions or views it will override the scaffold's version."


But in part 2, you explain the delete error by saying:
"I added a link to a delete action in the view template, but never created a delete action in the recipe controller."


So why did you have to create your own Delete method? Shouldn't it be there already?


In fact, I got the same "Unknown Action" error message that you did, when I used the keyword Delete in my code. But I discovered that the name of the method used to delete a record is actually: "Destroy", not "Delete". Using the "Destroy" keyword works, and you don't have to create your own method.


I discovered this keyword in the category/list screen. There, you see the list of your categories: Snack and Beverage, along with 3 links - Show, Edit, Destroy. And if you view the browser's status bar with your mouse over "Destroy", you'll see that Destroy is the actual method name used in the link, and not just a label on the page.


1 to 1 of 1
1 to 1 of 1