I have created a simple login form..........
form is like this..............
<% form_tag :controller => "user", :action =>
"login_submit" do %>
<p class="input_fields"><label>Username:
</label><input
id="user_username" name="user[username]" size="15"
type="text" /></p>
<p class="input_fields"><label>Password:
</label><input
id="user_password" name="user[password]" size="15"
type="password"
/></p><br clear="all" />
<%= submit_tag "Login"%>
<% end %>
********************************************************************
METHOD IN USER CONTROLLER IS LIKE THIS..............
def login_submit
if session[''user'']
@logged_in = true
else
@logged_in = false
end
@user = User.new(@params[''user''])
if @session[''user''] =
User.authenticate(@params[''user''][''username''],
@params[''user''][''password''])
flash[:notice] = l(:user_login_succeeded)
redirect_to :action => ''welcome''
else
@login = @params[''user''][''login'']
flash.now[:notice] = l(:user_login_failed)
end
end
*************************************************************************
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Apr 28, 9:04 pm, Manish Nautiyal <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> if @session[''user''] = User.authenticate(@params[''user''][''username''], > @params[''user''][''password''])Don''t use @session, @params etc. They were removed. Use session/params instead. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That looks like a good form :) On Mon, Apr 28, 2008 at 2:04 PM, Manish Nautiyal <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have created a simple login form.......... > > form is like this.............. > <% form_tag :controller => "user", :action => "login_submit" do %> > <p class="input_fields"><label>Username: </label><input > id="user_username" name="user[username]" size="15" type="text" /></p> > <p class="input_fields"><label>Password: </label><input > id="user_password" name="user[password]" size="15" type="password" > /></p><br clear="all" /> > > <%= submit_tag "Login"%> > <% end %> > ******************************************************************** > > METHOD IN USER CONTROLLER IS LIKE THIS.............. > > def login_submit > if session[''user''] > @logged_in = true > else > @logged_in = false > end > @user = User.new(@params[''user'']) > if @session[''user''] = User.authenticate(@params[''user''][''username''], > @params[''user''][''password'']) > flash[:notice] = l(:user_login_succeeded) > redirect_to :action => ''welcome'' > else > @login = @params[''user''][''login''] > flash.now[:notice] = l(:user_login_failed) > end > end > ************************************************************************* > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Apr 28, 9:04�pm, Manish Nautiyal <rails-mailing-l...@andreas-s.net> > wrote: >> � � if @session[''user''] = User.authenticate(@params[''user''][''username''], >> @params[''user''][''password'']) > > Don''t use @session, @params etc. They were removed. Use session/params > instead. > > Frednothing happen.............. i just remove wht u say ........but still same error......... NoMethodError in UserController#login_submit You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 29 Apr 2008, at 19:10, Manish Nautiyal wrote:> > Frederick Cheung wrote: >> On Apr 28, 9:04�pm, Manish Nautiyal <rails-mailing-l...@andreas- >> s.net> >> wrote: >>> � � if @session[''user''] = User.authenticate(@params[''user''] >>> [''username''], >>> @params[''user''][''password'']) >> >> Don''t use @session, @params etc. They were removed. Use session/ >> params >> instead. >> >> Fred > > nothing happen.............. > i just remove wht u say ........but still same error......... > > NoMethodError in UserController#login_submit > > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[]Learn to understand these errors: what line did it occur on. What is the object that is null and why is it null etc... Step through the code with the debugger. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 29 Apr 2008, at 19:10, Manish Nautiyal wrote: > >>> params >> You might have expected an instance of ActiveRecord::Base. >> The error occurred while evaluating nil.[] > > Learn to understand these errors: what line did it occur on. What is > the object that is null and why is it null etc... Step through the > code with the debugger. > > Fredhi..... this code is running in my office pc.....but whn i run same code in home pc.... it shows error.......can u tell me wht the main reason.......... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 30, 2008, at 2:14 PM, Manish Nautiyal wrote:> Frederick Cheung wrote: >> On 29 Apr 2008, at 19:10, Manish Nautiyal wrote: >> >>>> params >>> You might have expected an instance of ActiveRecord::Base. >>> The error occurred while evaluating nil.[] >> >> Learn to understand these errors: what line did it occur on. What is >> the object that is null and why is it null etc... Step through the >> code with the debugger. >> >> Fred > > hi..... > this code is running in my office pc.....but whn i run same code in > home > pc.... > it shows error.......can u tell me wht the main reason..........Send me your pc and I''d take a look ;-) Seriously, there''s no way that anyone here can help you with so little information. You''ll have to work it out on your own or trade excess punctuation for more detail. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
HERE IS ONE LOOK OF MY FORM WITH CONTROLLER & MODEL & FORM &
DATABASE
HERE IS MY ERROR -----
NoMethodError in UserController#login_submit
undefined method `authenticate'' for #<Class:0x36f6cbc>
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1532:in
`method_missing''
app/controllers/user_controller.rb:34:in `login_submit''
---------------------------------------------------------------------------------------------------------------------------
HERE IS MY USER CONTROLLER-----
class UserController < ApplicationController
layout "home"
def list
@user = User.find(:all)
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to :action => ''list''
else
redirect_to :action => ''new''
end
end
def login
@user = User.new
@user.username = params[:user][:username]
end
def login_submit
username = params[:user][:username]
password = params[:user][:password]
if session["user"] = User.authorize(username, password)
@user = User.find(session["user"].id)
@user.first_login = 1
@user.save
flash[:notice] = "You are now logged in"
redirect_to :action => ''create''
else
flash[:error] = "Incorrect username and/or password"
redirect_to :action => ''list''
end
end
end
------------------------------------------------------------------------------------------------------------------------
HERE IS MY USER MODEL---
class User < ActiveRecord::Base
validates_presence_of :username, :message=>"User Name will not b
blank"
validates_presence_of :password, :message=>"Password cannot be
blank"
end
------------------------------------------------------------------------------------------------------
HERE IS MY FORM ----
<div>
<h1>Login Section</h1>
<% form_tag :controller => "user", :action =>
"login_submit" do %>
<p class="input_fields"><label>Username:
</label><input
id="user_username" name="user[username]" size="15"
type="text" /></p>
<p class="input_fields"><label>Password:
</label><input
id="user_password" name="user[password]" size="15"
type="password"
/></p><br clear="all" />
<%= submit_tag "Login"%>
<% end %>
</div>
------------------------------------------------------------
CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(64) NOT NULL,
`password` varchar(64) NOT NULL,
`name` varchar(200) NOT NULL,
`email` varchar(150) NOT NULL,
`created_at` datetime default NULL,
PRIMARY KEY (`id`)
) ;
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
What Prasad said! (Please don''t double-post your issues) -Rob On May 1, 2008, at 2:37 AM, Prasad wrote:> You should have a method authenticate defined in User model. > > In your case, authenticate method must be defined in User model as > > class User < ActiveRecord::Base > validates_presence_of :username, :message=>"User Name will not > bblank" > validates_presence_of :password, :message=>"Password cannot be > blank" > > # # # # Authenticate method # # # > def self.authenticate(login, pass) > find(:first, :conditions=>["login = ? AND password = ?", login, > pass]) # login, password are your users table fields.. > end > > endOn May 1, 2008, at 12:16 AM, Manish Nautiyal wrote:> HERE IS ONE LOOK OF MY FORM WITH CONTROLLER & MODEL & FORM & DATABASE > > HERE IS MY ERROR ----- > > NoMethodError in UserController#login_submit > > undefined method `authenticate'' for #<Class:0x36f6cbc> > > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > base.rb:1532:in > `method_missing'' > app/controllers/user_controller.rb:34:in `login_submit'' > > > --------------------------------------------------------------------------------------------------------------------------- > HERE IS MY USER CONTROLLER----- > > class UserController < ApplicationController > > layout "home" > > def list > @user = User.find(:all) > end > > def new > @user = User.new > end > > def create > @user = User.new(params[:user]) > if @user.save > redirect_to :action => ''list'' > else > redirect_to :action => ''new'' > end > end > > def login > @user = User.new > @user.username = params[:user][:username] > end > > def login_submit > username = params[:user][:username] > password = params[:user][:password] > if session["user"] = User.authorize(username, password) > @user = User.find(session["user"].id) > @user.first_login = 1 > @user.save > flash[:notice] = "You are now logged in" > redirect_to :action => ''create'' > else > flash[:error] = "Incorrect username and/or password" > redirect_to :action => ''list'' > end > end > end > ------------------------------------------------------------------------------------------------------------------------ > HERE IS MY USER MODEL--- > > class User < ActiveRecord::Base > validates_presence_of :username, :message=>"User Name will not b > blank" > validates_presence_of :password, :message=>"Password cannot be blank" > end > > ------------------------------------------------------------------------------------------------------ > > HERE IS MY FORM ---- > > <div> > <h1>Login Section</h1> > <% form_tag :controller => "user", :action => "login_submit" do %> > <p class="input_fields"><label>Username: </label><input > > id="user_username" name="user[username]" size="15" type="text" /></p> > <p class="input_fields"><label>Password: </label><input > > id="user_password" name="user[password]" size="15" type="password" > /></p><br clear="all" /> > > <%= submit_tag "Login"%> > <% end %> > > </div> > > ------------------------------------------------------------ > CREATE TABLE `users` ( > `id` int(11) NOT NULL auto_increment, > `username` varchar(64) NOT NULL, > `password` varchar(64) NOT NULL, > `name` varchar(200) NOT NULL, > `email` varchar(150) NOT NULL, > `created_at` datetime default NULL, > PRIMARY KEY (`id`) > ) ;--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---