Forum: Ruby on Rails AJAX: link_to_remote creates a post request

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
515d99da5168da6627a63735bae09357?d=identicon&s=25 Jon Hope (jonmidhir)
on 2009-04-13 23:15
I've tried googling this and simply can't believe this problem hasn't
come up before but I'll explain it as I'm getting it here.

I'm using RESTful actions in my controllers and trying to introduce a
little AJAX fun to my app. Basically plan is for the user to click a
link which shows a div containing a form to fill in, the form is then
submitted by AJAX and the page updated accordingly.

If I create a link using link_to_remote to show the div that contains
the form, it sends a post request to the server. This is fine so long as
there's no javascript response to handle the request in the CREATE
method, the request presumably just gets ignored.

However now the form is being submitted by AJAX and it sends a js
formatted post request to the controller, which interprets the request
and updates the page accordingly. Now when I click the link to show the
form, that post request gets sent and handled by the create action. It
doesn't pass validations as there's no data in it and just causes a
blank page to load.

So instead of even seeing the form the user gets redirected to a blank

I know I could probably just change the link_to_remote action to a get
request instead but that doesn't seem like a solid solution. I mean what
if I want a seperate js get request as well?

Is there any way to use link_to_remote to create AJAX animations and
show/hide elements without creating any request to the server?

Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2009-04-14 00:10
(Received via mailing list)
On Mon, Apr 13, 2009 at 2:15 PM, Jon Hope
<> wrote:

> Is there any way to use link_to_remote to create AJAX animations and
> show/hide elements without creating any request to the server?

AJAX /means/ creating a request to the server. If you just want to do
"animations and show/hide elements" use plain old JavaScript.

Hassan Schroeder ------------------------
4c438a80fc30661ad619ea177cf9cbd0?d=identicon&s=25 Freddy Andersen (Guest)
on 2009-04-14 00:13
(Received via mailing list)
You are looking for link_to_remote that will give you the ability to
show/hide a div.

Here is an example to just show a div

link_to_function("show form", nil) { |page|
page.visual_effect :toggle_blind, 'form_div' }

If you want you can have a hide link inside the div that his hidden so
they can close the form again..
515d99da5168da6627a63735bae09357?d=identicon&s=25 Jon Hope (jonmidhir)
on 2009-04-14 01:13
Thanks guys, major brain malfunction there!
This topic is locked and can not be replied to.