# Calling a controller method in javascript

**URL:** <https://www.ruby-forum.com/t/calling-a-controller-method-in-javascript/141654>\
**Category:** Rails\
**Created:** [June 28, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/calling-a-controller-method-in-javascript/141654 "2008-06-28T14:06:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shripad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@Shripad](https://www.ruby-forum.com/u/Shripad)\
**Post date:** [June 28, 2008, 2:06pm UTC](https://www.ruby-forum.com/t/calling-a-controller-method-in-javascript/141654/1 "2008-06-28T14:06:56Z")

</div>

Hi all,

I want to call a method present in ROR controller in my javascript for  
performing some logout activities. How can I do this  
Please help me

Thanks and regards,

---

<div class="post-metadata">

**Author:** ![Shripad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@Shripad](https://www.ruby-forum.com/u/Shripad)\
**Post date:** [June 28, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/calling-a-controller-method-in-javascript/141654/2 "2008-06-28T14:14:34Z")

</div>

On Jun 28, 4:59 am, Shripad [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,
> 
> I want to call a method present in ROR controller in my javascript for  
> performing some logout activities. How can I do this  
> Please help me

Use an ajax request (lookup link\_to\_remote, remote\_function etc…)

Fred

---

<div class="post-metadata">

**Author:** ![Shripad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@Shripad](https://www.ruby-forum.com/u/Shripad)\
**Post date:** [June 29, 2008, 9:11am UTC](https://www.ruby-forum.com/t/calling-a-controller-method-in-javascript/141654/3 "2008-06-29T09:11:08Z")

</div>

On Jun 28, 5:14 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Jun 28, 4:59 am, Shripad [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:\> Hi all,
> 
> > I want to call a method present in ROR controller in my javascript for  
> > performing some logout activities. How can I do this  
> > Please help me
> 
> Use an ajax request (lookup link\_to\_remote, remote\_function etc…)
> 
> Fr  
> ed

hi,

thanks for your urgent reply Frederick  
but, i don’t know how to use ajax for the same,  
will u please give me details abt this.

Thanks and regards,  
Shripad

---

<div class="post-metadata">

**Author:** ![Shripad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@Shripad](https://www.ruby-forum.com/u/Shripad)\
**Post date:** [June 29, 2008, 3:40pm UTC](https://www.ruby-forum.com/t/calling-a-controller-method-in-javascript/141654/4 "2008-06-29T15:40:04Z")

</div>

On 29 Jun 2008, at 08:10, Shripad wrote:

> > > performing some logout activities. How can I do this  
> > > but, i don’t know how to use ajax for the same,  
> > > will u please give me details abt this.

Read the API docs for the funcions I listed.

Fred

---

<div class="post-metadata">

**Author:** ![Shripad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@Shripad](https://www.ruby-forum.com/u/Shripad)\
**Post date:** [June 30, 2008, 6:31am UTC](https://www.ruby-forum.com/t/calling-a-controller-method-in-javascript/141654/5 "2008-06-30T06:31:21Z")

</div>

Hi,

I have implemented the methods u listed, but it is still not solved my  
purpose

what I want to do is, when user close the browser the user should be  
loged out  
but it is not doing that.

will you please suggest me a solution.

Thanks and Regards  
Shripad

On Jun 29, 6:39 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Shripad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@Shripad](https://www.ruby-forum.com/u/Shripad)\
**Post date:** [June 30, 2008, 9:59am UTC](https://www.ruby-forum.com/t/calling-a-controller-method-in-javascript/141654/6 "2008-06-30T09:59:45Z")

</div>

On Jun 30, 5:31 am, Shripad [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I have implemented the methods u listed, but it is still not solved my  
> purpose
> 
> what I want to do is, when user close the browser the user should be  
> loged out  
> but it is not doing that.

Could have saved everyone some time if you’d said that to begin with.  
There is window.onclose, although you can’t be 100% sure it will be  
called (eg browser crashes, user loses network connection etc…)

Fred
