Forum: Ruby on Rails scaffold uses link_to for destroy

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-01-08 19:07
(Received via mailing list)
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
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-08 19:47
Peter Michaux 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'.
2dd904ec5981c31e7bb7a5743a53caf8?d=identicon&s=25 Bruce Balmer (brucebalmer)
on 2006-01-08 20:23
(Received via mailing list)
Kevin:

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

bruce
6edd67c92a1dab5eb23fed79f3c18564?d=identicon&s=25 David Heinemeier Hansson (Guest)
on 2006-01-08 21:14
(Received via mailing list)
> 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 Hansson
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
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-01-09 23:55
(Received via mailing list)
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
This topic is locked and can not be replied to.