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.
Sam D. (Guest)
on 2006-05-10 02: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.
Manuel H. (Guest)
on 2006-05-10 02:35
(Received via mailing list)
Am 10.05.2006 um 00:11 schrieb Sam D.:

> 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
Kian (Guest)
on 2006-05-10 03:30
(Received via mailing list)
Manuel H. <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.
Lee I. (Guest)
on 2006-05-10 03:42
(Received via mailing list)
Sam D. 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.