# Invoke a controller def from view without clicking any link

**URL:** <https://www.ruby-forum.com/t/invoke-a-controller-def-from-view-without-clicking-any-link/167658>\
**Category:** Rails\
**Created:** [May 11, 2009, 9:01am UTC](https://www.ruby-forum.com/t/invoke-a-controller-def-from-view-without-clicking-any-link/167658 "2009-05-11T09:01:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 11, 2009, 9:01am UTC](https://www.ruby-forum.com/t/invoke-a-controller-def-from-view-without-clicking-any-link/167658/1 "2009-05-11T09:01:48Z")

</div>

Hi  
I have a controller def like

def graph\_render  
get\_flash\_chat\_objects  
respond\_to do |format|  
format.js do  
render :update do |page|  
page[:graph\_div].replace\_html :partial =\> “summary\_graph”  
end  
end  
end  
end

```
So clearly this just accept an ajax request and do the above action

```

This is working But what I would like to know how can I invoke it from  
view without clicking a link or like that

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 11, 2009, 10:43am UTC](https://www.ruby-forum.com/t/invoke-a-controller-def-from-view-without-clicking-any-link/167658/2 "2009-05-11T10:43:00Z")

</div>

On May 11, 8:01 am, Sijo Kg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> So clearly this just accept an ajax request and do the above action
> 
> ```
> 
> This is working But what I would like to know how can I invoke it from  
> view without clicking a link or like that

Well unless you have a javascript timer on the page that fires off  
your ajax request, it’s going to have to happen in response to some  
event (not necessarily a mouse click, could be page load, mouseover,  
keydown etc…)

Fred

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 11, 2009, 10:50am UTC](https://www.ruby-forum.com/t/invoke-a-controller-def-from-view-without-clicking-any-link/167658/3 "2009-05-11T10:50:40Z")

</div>

Hi  
In my partial I tried like

But this onload not working Since I tried with an alert first Could  
you please tell how can I do this?

Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 12, 2009, 1:26pm UTC](https://www.ruby-forum.com/t/invoke-a-controller-def-from-view-without-clicking-any-link/167658/4 "2009-05-12T13:26:54Z")

</div>

Use prototype functions to handle the onload events. It is better  
than plugging in onload code into your HTML tags. Look at the online  
documentation for examples. You can use either the dom:loaded event  
or the window:onload event.
