How do i use button_to_function

Hii all ,

          I am trying to create a button that, when clicked on, calls a method in a controller . I am thinking that button_to_function is good to use for that i made htnl viwe like

<h1>File Upload</h1>

<p><label for="upload_file">Select File</label> : <%= file_field 'upload', 'datafile' %></p> <%= button_to_function "UploadFile","alert('Hello world!')"%> <%=button_to_function 'upload', remote_function({:action =>'uploadFile'}, :controller => 'UploadController') %>

but when i clicked on upload button nothing happen could anyone suggest me how to this

Amit Tomar wrote in post #955655:

Hii all ,

          I am trying to create a button that, when clicked on, calls a method in a controller . I am thinking that button_to_function is good to use for that i made htnl viwe like

<h1>File Upload</h1>

<p><label for="upload_file">Select File</label> : <%= file_field 'upload', 'datafile' %></p> <%= button_to_function "UploadFile","alert('Hello world!')"%> <%=button_to_function 'upload', remote_function({:action =>'uploadFile'}, :controller => 'UploadController') %>

but when i clicked on upload button nothing happen could anyone suggest me how to this

Hi

You can use button_to_function with remote_function like

<%= button_to_function 'Click me', remote_function(:url=>{:action => 'uploadFile', :controller => 'UploadController'}} =>

remote_function is same options as link_to_remote and generates the an ajax call. You'll want to read about rjs for the final step of your problem

Good Luck :wink: -Ganesh K

Ganesh Kathare wrote in post #955659:

Amit Tomar wrote in post #955655:

Hii all ,

          I am trying to create a button that, when clicked on, calls a method in a controller . I am thinking that button_to_function is good to use for that i made htnl viwe like

<h1>File Upload</h1>

Thanks Ganesh i don't but its working for me Actully in my rails application i displayed a messagebox using win32api but i am not to produce it at client site do you have any idea how should i do that