How to use remote_function?

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs