# Event Handlers in ruby on rails

**URL:** <https://www.ruby-forum.com/t/event-handlers-in-ruby-on-rails/103757>\
**Category:** Rails\
**Created:** [May 10, 2007, 12:29am UTC](https://www.ruby-forum.com/t/event-handlers-in-ruby-on-rails/103757 "2007-05-10T00:29:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bunsenator](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/eb8c5e/32.png) [@bunsenator](https://www.ruby-forum.com/u/bunsenator)\
**Post date:** [May 10, 2007, 12:29am UTC](https://www.ruby-forum.com/t/event-handlers-in-ruby-on-rails/103757/1 "2007-05-10T00:29:18Z")

</div>

Does anyone know how I can implement event handlers in rails? I’m a  
super newbie to programming in general and wanted to start with a  
language that is really simple.

Besides that, I have a little javascript knowledge.

So I was wondering how I could integrate event handlers into my pages?

---

<div class="post-metadata">

**Author:** ![bunsenator](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/eb8c5e/32.png) [@bunsenator](https://www.ruby-forum.com/u/bunsenator)\
**Post date:** [May 10, 2007, 1:29am UTC](https://www.ruby-forum.com/t/event-handlers-in-ruby-on-rails/103757/2 "2007-05-10T01:29:25Z")

</div>

Auston Bunsen wrote:

> Does anyone know how I can implement event handlers in rails? I’m a  
> super newbie to programming in general and wanted to start with a  
> language that is really simple.
> 
> Besides that, I have a little javascript knowledge.
> 
> So I was wondering how I could integrate event handlers into my pages?

Ok, I figured out how to include event handlers, it’s like this"\<%=  
start\_form\_tag({:action=\>‘update’, :id=\>@alert},  
:onsubmit=\>‘getComment()’) %\>" but now:

If I want my event handler to trigger an ajax call that works with an  
action/method in my rails controller?

---

<div class="post-metadata">

**Author:** ![bunsenator](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/eb8c5e/32.png) [@bunsenator](https://www.ruby-forum.com/u/bunsenator)\
**Post date:** [May 10, 2007, 2:44am UTC](https://www.ruby-forum.com/t/event-handlers-in-ruby-on-rails/103757/3 "2007-05-10T02:44:13Z")

</div>

Take a look at link\_to\_remote. It has a hooks for setting javascript  
callbacks to run while loading, on success, on failure, etc. Then just  
add the action to handle it on the server side and you’re all set.

b

---

<div class="post-metadata">

**Author:** ![bunsenator](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/eb8c5e/32.png) [@bunsenator](https://www.ruby-forum.com/u/bunsenator)\
**Post date:** [May 10, 2007, 3:02am UTC](https://www.ruby-forum.com/t/event-handlers-in-ruby-on-rails/103757/4 "2007-05-10T03:02:42Z")

</div>

Ben M. wrote:

> Take a look at link\_to\_remote. It has a hooks for setting javascript  
> callbacks to run while loading, on success, on failure, etc. Then just  
> add the action to handle it on the server side and you’re all set.
> 
> b

I’m very sorry. I should have been more specific.

I know how to use, an onclick even handler because that comes with  
rails. but for instance, in a form, i’ll have a select element with 3  
options, and if a certain option is selected, it will prompt javascript  
to have an additional field fade in.

I’m guessing hardcoding it will be the easiest.
