Forum: Ruby on Rails Javascript help

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.
C5de46ba2bbb6ac7a0744ddae42d60f5?d=identicon&s=25 DanC (Guest)
on 2008-10-08 22:07
(Received via mailing list)
I have a blog on my site and would like readers to be able to
recommend comments.

I added an integer column to my comments table called 'agree' and have
a link to a controller which increments the entry in that column by
one on each click.

I just use @comment.increment!("agree") and then redirect back to the
blog.

However, I am paginating the comments and if you recommend a comment
on page 2, for example, the redirect goes back to the default page 1.

Is there a way to increment the table entry using some ajax in the
controller?

I am quite unfamiliar with Ajax and haven't been able to get it to
work.

Thanks

Dan
C5de46ba2bbb6ac7a0744ddae42d60f5?d=identicon&s=25 DanC (Guest)
on 2008-10-08 22:53
(Received via mailing list)
Have got a work around now using {redirect_to :back} in the controller
but would still like to hear about a javascript option if anyone has
advice.

Dan
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2008-10-08 23:28
(Received via mailing list)
On Oct 8, 2008, at 1:07 PM, DanC wrote:

>
> However, I am paginating the comments and if you recommend a comment
> on page 2, for example, the redirect goes back to the default page 1.
>
> Is there a way to increment the table entry using some ajax in the
> controller?
>
> I am quite unfamiliar with Ajax and haven't been able to get it to
> work.

Yes.  Look at link_to_remote.  You tell it what action to hit and can
then tell it what div to update or some other custom "sucess" action.
In your case, I'd replace the "i agree" link with a "thanks" text or
something.

-philip
This topic is locked and can not be replied to.