I’ve spent hours on this, and I can’t figure it out. I’m trying to
create a simple login system. Here’s my accounts controller.
class AccountsController < ApplicationController
ssl_required :login
def login
if !(params[:username] and params[:password])
flash[:error] = “Username or password cannot be blank.”
redirect_to :action => :index
return
end
username = params[:username]
hashed_password = "hello" #Account.hash(params[:password])
account = Account.find_by_username_and_hashed_password(username,
hashed_password)
if account == nil
flash[:error] = "Incorrect username or password."
redirect_to :action => :index
return
end
session[:user_id] = account.id
redirect_to :controller => :home
end
def logout
session[:user_id] = nil
flash[:notice] = “You have logged out.”
redirect_to :controller => :home
end
end
The logout function works fine. The first part of the login function,
the part that tests to make sure that a username and password are
present, works fine as well. However, if I pass username and password
parameters to the function (regardless if they correspond to a real
account or not), everything blows up in my face. In fact, my whole
application permanently crashes until I run “rake db:sessions:clear”.
Even if I restart mongrel and Apache, my application still doesn’t
work until the sessions are cleaned out. My Account.hash and
Account.find_by_username_and_hashed_password functions both work fine,
and I tried turning them off. No luck.
Any ideas?
Oh, and the errors I get in the mongrel console are:
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment…
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. INT => stop (no restart).
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
Sat Nov 10 13:26:13 -0500 2007: Error calling Dispatcher.dispatch
#<ArgumentErro
r: wrong number of arguments (0 for 1)>
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/ba
se.rb:1318:in hash' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/ba se.rb:1318:in[]’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/ba
se.rb:1318:in subclasses' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/ba se.rb:1319:insubclasses’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/
action_controller/
routing.rb:351:in inject' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/ba se.rb:1319:ineach’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/ba
se.rb:1319:in inject' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/ba se.rb:1319:insubclasses’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/ba
se.rb:280:in reset_subclasses' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/dispatcher.rb: 57:inres
et_application!’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/dispatcher.rb:
115:in re set_after_dispatch' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/dispatcher.rb: 50:indis
patch’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/
mongrel/rails.
rb:78:in process' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel/rails. rb:76:insynchronize’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/
mongrel/rails.
rb:76:in process' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel.rb:618 :inprocess_client’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/
mongrel.rb:617
:in each' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel.rb:617 :inprocess_client’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/
mongrel.rb:736
:in run' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel.rb:736 :ininitialize’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/
mongrel.rb:736
:in new' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel.rb:736 :inrun’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/
mongrel.rb:720
:in initialize' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel.rb:720 :innew’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/
mongrel.rb:720
:in run' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel/config urator.rb:271:inrun’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/
mongrel/config
urator.rb:270:in each' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel/config urator.rb:270:inrun’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/
mongrel_rails:
127:in run' C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/lib/ mongrel/comman d.rb:211:inrun’
C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/bin/
mongrel_rails:
243
C:/INSTAN~1/ruby/bin/mongrel_rails:16:in `load’
C:/INSTAN~1/ruby/bin/mongrel_rails:16
Thanks!
