# called javascript method and ruby method with 1 button?

**URL:** <https://discuss.rubyonrails.org/t/called-javascript-method-and-ruby-method-with-1-button/12266>\
**Category:** rubyonrails-talk\
**Created:** [April 28, 2007, 11:24am UTC](https://discuss.rubyonrails.org/t/called-javascript-method-and-ruby-method-with-1-button/12266 "2007-04-28T11:24:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Mear1](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@Chris\_Mear1](https://discuss.rubyonrails.org/u/Chris_Mear1)\
**Post date:** [April 28, 2007, 11:24am UTC](https://discuss.rubyonrails.org/t/called-javascript-method-and-ruby-method-with-1-button/12266/1 "2007-04-28T11:24:50Z")

</div>

You can use button\_to\_function with remote\_function to create a button that will use Ajax to call an action in your controller.

The method remote\_function takes the same parameters as link\_to\_remote, which means that you can then use parameters like :before, :after, :complete, etc. to call arbitrary JavaScript at various points during the Ajax request.

For example:

\<%= button\_to\_function("Click me", remote\_function(:url =\> {:action =\> :do\_stuff}, :before =\> "myJavaScriptFunction()")) %\>

Chris
