# Button\_to\_function question

**URL:** <https://www.ruby-forum.com/t/button-to-function-question/122066>\
**Category:** Rails\
**Created:** [December 4, 2007, 9:24am UTC](https://www.ruby-forum.com/t/button-to-function-question/122066 "2007-12-04T09:24:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [December 4, 2007, 9:24am UTC](https://www.ruby-forum.com/t/button-to-function-question/122066/1 "2007-12-04T09:24:03Z")

</div>

Hey everybody,  
I am trying to create a button that, when clicked on, calls a method  
in a controller then changes the image on the button without a page  
load. I was thinking that button\_to\_function might be a good  
contender for this but I don’t yet know how to make it talk to a  
controller, and on success change the image of the button. Can anyone  
help me out with this problem?

Thanks,  
John

---

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [December 4, 2007, 9:33am UTC](https://www.ruby-forum.com/t/button-to-function-question/122066/2 "2007-12-04T09:33:19Z")

</div>

Jables wrote:

> Hey everybody,  
> I am trying to create a button that, when clicked on, calls a method  
> in a controller then changes the image on the button without a page  
> load. I was thinking that button\_to\_function might be a good  
> contender for this but I don’t yet know how to make it talk to a  
> controller, and on success change the image of the button. Can anyone  
> help me out with this problem?
> 
> Thanks,  
> John

If you need to talk to controller, then it will load the page right?  
Just put some helper method and call it in the button\_to\_function. Iam  
not sure.

---

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [December 4, 2007, 9:46am UTC](https://www.ruby-forum.com/t/button-to-function-question/122066/3 "2007-12-04T09:46:17Z")

</div>

On Dec 4, 8:33 am, Ayyanar Aswathaman \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> Jables wrote:
> 
> > Hey everybody,  
> > I am trying to create a button that, when clicked on, calls a method  
> > in a controller then changes the image on the button without a page  
> > load. I was thinking that button\_to\_function might be a good  
> > contender for this but I don’t yet know how to make it talk to a  
> > controller, and on success change the image of the button. Can anyone  
> > help me out with this problem?

button\_to\_function ‘Click me’, remote\_function(:url=\>{:action =\>  
‘foo’, :controller =\> ‘bar’}}

remote\_function takes basically the same options as link\_to\_remote and  
generates the javascript for an ajax call. You’ll want to read about  
rjs for the final step of your problem

Fred
