Destroy? Delete? What's going on here? Rails 2.3.5

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-03-07T10:49:01Z Indexed on 2010/03/16 8:26 UTC
Read the original article Hit count: 141

Filed under:

I am new to rails. My rails version is 2.3.5. I found usage like:

In controller, a destroy method is defined and in view, you can use :action => "delete" to fire that method. Isn't the action name has to be the same as the method name? Why delete is mapped to destroy?

Again, in my controller, I define a method called destroy to delete a record. In a view, I have <%= link_to "remove", :action => 'destroy', :id => myrecord %>. But it never works in practice. Every time I press the remove link, it redirects me to the show view, showing the record's content. I am pretty sure that my destroy method is:

def destroy @myobject = MyObject.find(params[:id]) @myobject.destroy @redirect_to :action = 'index' end

If I change the method name from destroy to something like remove_me and change the action name to remove_me in the view, everything works as expected.

In the above two wired problems, I am sure there is no tricky rountting set in my configuration.

All in all, seems the destroy and delete are mysterious keywords in rails. Anyone can explain this to me? Thank you very much.

© Stack Overflow or respective owner

Related posts about ruby-on-rails