have user_cotnroller
class UserController < ApplicationController
def authenticate
if request.post?
#User.new(params[:userform]) will create a new object of User,
retrieve values from the form and store it variable @user.
@user = User.new(params[:userform])
#@user = User.find_by_id(params[:id])
#find records with username,password
valid_user = User.find(:first,:conditions => [“username = ? and
password = ?”,@user.username, @user.password])
#if statement checks whether valid_user exists or not
if valid_user
#creates a session with username
session[:user_id]=valid_user.username
#data = { :success => 'true', :msg => "Welcome,
#{params[:username]}!" }
#redirects the user to our private page.
redirect_to :action => ‘private’
else
flash[:notice] = “Invalid User/Password”
#data = { :failure => ‘true’, :msg => “Username or Password
wrong!” }
redirect_to :action=> ‘login’
end
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
Have login.js
var userform = new Ext.form.FormPanel({
baseCls: 'x-plain',
labelWidth: 75,
id: 'userform',
method: 'POST',
url:'/user/authenticate',
defaultType: 'textfield',
items: [{
fieldLabel: 'Login',
name: 'username',
anchor:'90%' // anchor width by percentage
} ,{
fieldLabel: 'Password',
name: 'password',
inputType: 'password',
anchor: '90%' // anchor width by percentage
}],
buttons: [{
text: 'Login',
handler: function() {
userform.getForm().submit(
{
method: 'POST',
waitMsg:'Submitting...',
reset : false,
success : function(form, action) {
Ext.Msg.alert('Bravo', action.result.msg);
loginWindow.close();
/*var redirect = '/admin/welcome';
window.location = redirect;
*/
},
failure: function(form, action)
{Ext.Msg.alert(‘Error’, action.result.msg)}
});
}
}]
});
var loginWindow = new Ext.Window({
title: 'Login',
width: 300,
height:140,
closable:false,
minWidth: 300,
minHeight: 140,
layout: 'fit',
id: 'userform',
plain:true,
modal:true,
bodyStyle:'padding:5px;',
items: userform
});
Ext.onReady(function(){
loginWindow.show(this);
});
login page
<script type="text/javascript" src="/ext/adapter/ext/ext-
base.js">
</
script>
<% if flash[:notice] %>
<div style="font-family:'Trebuchet MS'; color:#FF0000; font-size:
14px;">
<%= flash[:notice] %>
<% end %>
<!--creates form, exectues the authenticate method when the submit
button is clicked–>
<%= form_tag :action=>‘authenticate’ %>
User name:
<%= text_field(“userform”, “username”,:size=>“20” ) %>
Password:
<%= password_field(“userform”, “password”,:size=>“20” )
%>
SO, question is.
Without extJS (login,js) everything looks nice. Sessions works and so
on. But i want make form in extJs, i made it, but when i put my right
data (user:test,pw:test) i get in console:
Processing UserController#authenticate (for 127.0.0.1 at
2011-04-14 13:21:19) [POST]
Parameters: {“username”=>“test”, “password”=>“test”}
User Columns (0.5ms) SHOW FIELDS FROM users
User Load (0.2ms) SELECT * FROM users
WHERE (username = NULL
and password = NULL) LIMIT 1
My form doesn’t look my data:(