Forum: Ruby on Rails send a POST off a link, not a button.

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.
036be8d5d83a98e546b98d64e3fd6c20?d=identicon&s=25 Sam Donaldson (Guest)
on 2006-05-10 00:11
(Received via mailing list)
Hi,

Got a question about how the book suggests sending POST requests using a
form whenever one intents to change some database state.  So I converted
a
bunch of links to forms which ended up creating buttons.  I was
wondering if
there was a way to keep them links rather than buttons but still use
POST in
a form?

thanks.
54532f023496410e0d7b1add5561ba45?d=identicon&s=25 Manuel Holtgrewe (Guest)
on 2006-05-10 00:35
(Received via mailing list)
Am 10.05.2006 um 00:11 schrieb Sam Donaldson:

> Hi,
>
> Got a question about how the book suggests sending POST requests
> using a form whenever one intents to change some database state.
> So I converted a bunch of links to forms which ended up creating
> buttons.  I was wondering if there was a way to keep them links
> rather than buttons but still use POST in a form?

Call a JavaScript that does an XmlHttpRequest (aka AJAX request)
which is submitted via POST.

*m
27f8beb57f4d56d328749b51ac886d2c?d=identicon&s=25 Kian (Guest)
on 2006-05-10 01:30
(Received via mailing list)
Manuel Holtgrewe <purestorm@...> writes:

> > rather than buttons but still use POST in a form?
>
> Call a JavaScript that does an XmlHttpRequest (aka AJAX request)
> which is submitted via POST.
>
> *m
>

Or easier, your link should look like this:

<a href='document.forms[0].submit();'>Link Name</a>

This submits the first form on the page. You can also specify forms by
name or
id I think, but you typically only have one form per page anyway.
1cbcd04f1aa12775ce0f51d847bb4849?d=identicon&s=25 Lee Iverson (leei)
on 2006-05-10 01:42
(Received via mailing list)
Sam Donaldson wrote:
> Hi,
>
> Got a question about how the book suggests sending POST requests using
> a form whenever one intents to change some database state.  So I
> converted a bunch of links to forms which ended up creating buttons.
> I was wondering if there was a way to keep them links rather than
> buttons but still use POST in a form?
Try link_to("Destroy!", {:action => 'destroy'}, :post => true).

This will automagically create the javascript to turn the link in to a
POST method.
This topic is locked and can not be replied to.