# Javascript help

**URL:** <https://www.ruby-forum.com/t/javascript-help/150466>\
**Category:** Rails\
**Created:** [October 8, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/javascript-help/150466 "2008-10-08T22:07:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@DanC](https://www.ruby-forum.com/u/DanC)\
**Post date:** [October 8, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/javascript-help/150466/1 "2008-10-08T22:07:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DanC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@DanC](https://www.ruby-forum.com/u/DanC)\
**Post date:** [October 8, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/javascript-help/150466/2 "2008-10-08T22:53:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DanC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@DanC](https://www.ruby-forum.com/u/DanC)\
**Post date:** [October 8, 2008, 11:28pm UTC](https://www.ruby-forum.com/t/javascript-help/150466/3 "2008-10-08T23:28:35Z")

</div>

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
