Scaffold uses link_to for destroy


#1

Hi,

I wonder why scaffolding uses a link_to tag for the destroy links.
Seems like these should be POST requests with button_to. The Rails
book dedicates pages 335-337 to this very issue.

Peter


#2

Peter M. wrote:

Hi,

I wonder why scaffolding uses a link_to tag for the destroy links.
Seems like these should be POST requests with button_to. The Rails
book dedicates pages 335-337 to this very issue.

Peter

The scaffold is intended to be a quick and dirty implementation to get
things up and running. The intent is for the user to gradually replace
scaffold operations with their own (and presumably better) code. In
development mode

That said, I’m certain a signficant chunk of scaffold code will not be
replaced in some live applications. It would certainly make sense to
put in minor fixes like that as an example of good coding practices at
least.

My guess is that the scaffold hasn’t been updated in quite some time and
that this is a legacy thing.

FYI, you can make ‘link_to’ generate post requests instead of get
requests, so you don’t really need to use ‘button_to’.


#3

Kevin:

How do you get link_to to generate a post request? That would seem
useful in light of this discussion.

bruce


#4

How do you get link_to to generate a post request? That would seem
useful in light of this discussion.

link_to “Destroy”, { :action => “destroy” }, :post => true

David Heinemeier H.
http://www.loudthinking.com – Broadcasting Brain
http://www.basecamphq.com – Online project management
http://www.backpackit.com – Personal information manager
http://www.rubyonrails.com – Web-application framework


#5

Bruce

> How do you get link_to to generate a post request?

An alternative is to replace
link_to
by
button_to

=> Rails creates a form and a button to reach the link target.

Alain