# How to use remote\_function?

**URL:** <https://www.ruby-forum.com/t/how-to-use-remote-function/196982>\
**Category:** Rails\
**Created:** [July 10, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/how-to-use-remote-function/196982 "2009-07-10T23:19:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlovel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f05b48/32.png) [@jlovel](https://www.ruby-forum.com/u/jlovel)\
**Post date:** [July 10, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/how-to-use-remote-function/196982/1 "2009-07-10T23:19:14Z")

</div>

I am trying to make a very simple login page that has light-box like  
features. The only thing I cannot get to work is the behavior of the  
actual login button.  
When you click on it it does nothing. I simply want to submit the info  
given by the client and redirect either to a private page or make the  
client log in again. Here is the code for my log in box view:

User name: \<%= text\_field("userform", "user\_name",:size=\>"20" ) %\>  
Password: \<%= password\_field("userform", "password",:size=\>"20" ) %\>  
 \<%= javascript\_include\_tag :defaults %\> \<%= submit\_tag 'LOG IN', :onclick =\>remote\_function(:url =\> {:action =\> :authenticate, } ) %\>  

And here is the code from my controller for the authentication action I  
am calling on:

class UserController \< ApplicationController  
def authenticate  
@user = User.new(params[:userform])  
valid\_user = User.find(:first,:conditions =\> ["user\_name = ? and  
password = ? ",@user.user\_name, @user.password])  
if valid\_user  
session[:user\_id]=valid\_user.user\_name  
redirect\_to :action =\> ‘private’  
else  
flash[:notice] = “Invalid User/Password”  
redirect\_to :action=\> ‘login’  
end  
end  
def login  
end  
def private  
if !session[:user\_id]  
redirect\_to :action=\> ‘login’  
end  
end  
def logout  
if session[:user\_id]  
reset\_session  
redirect\_to :action=\> ‘login’  
end  
end  
end

When I tried typing the code  
submit\_tag ‘LOG IN’, :onclick =\>remote\_function(:url =\>  
{:action =\> :authenticate, } )  
into irb, I got this error message:  
NoMethodError: undefined method `remote\_function’ for main:Object

There may be a simple error that I am making, as I am pretty new to the  
ruby language. Also, if anyone knows another way to do this that will  
work with the partial rendering I use to display the login box, that  
would be fine, too.

---

<div class="post-metadata">

**Author:** ![jlovel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f05b48/32.png) [@jlovel](https://www.ruby-forum.com/u/jlovel)\
**Post date:** [July 11, 2009, 12:37am UTC](https://www.ruby-forum.com/t/how-to-use-remote-function/196982/2 "2009-07-11T00:37:07Z")

</div>

Hi Julia,

On Fri, 2009-07-10 at 23:19 +0200, Julia L. wrote:

As far as your view, take a look at form\_remote\_tag or form\_remote\_for.

HTH,  
Bill
