Wrong number of arguments (1 for 0)

I’m getting a wrong number of arguments (1 for 0) error. This happens
when I attempt to login to my app. Also, I upgraded to Ruby 1.8.6, from
1.8.2 (i think)
Heres the code:

— login.rhtml

<% form_tag do %>

Sign-in to BancOffice
Company Code: <%= text_field_tag :account_code, params[:account_code] %>
User name: <%= text_field_tag :username, params[:username] %>
Password: <%= password_field_tag :password, params[:password] %>
<%= submit_tag "Login" %>
<% end %>

logincontroller.rb

def login
session[:user_id] = nil
if request.post?
employee = Employee.authenticate(params[:username],
params[:password], params[:account_code])
if employee
session[:user_id] = employee.id
session[:account_id] = employee.account_id
@option = Option.find_by_employee_id(employee.id)
session[:admin_yn] = @option.admin_yn
redirect_to(:controller => “dashboard”, :action => “show”)
else
flash[:notice] = “Invalid user/password
combination”
end
end
end

employee.authenticate is line called for error


employee.rb

def self.authenticate(username, password, account_code)
if employee = find(:first, :include => [ :account, :options ],
:conditions => [ “employees.deleted_yn = 0” + " AND
employees.username = ?" + " AND accounts.account_code = ?",
username, account_code ])
if employee
expected_password = encrypted_password(password, employee.salt)
if employee.hashed_password != expected_password
employee = nil
end
end
employee
end
end

if employee = find… is line called for error

Thanks

George P. wrote:

<% end %> session[:user_id] = employee.id
   if employee

Thanks

If you can post the stack trace from the error, that’ll help a lot.

One unrelated comment though; you don’t need to separate the different
strings and add them together in your find conditions. Just make it one
string…

[ “employees.deleted_yn = 0 AND employees.username = ? AND
accounts.account_code = ?”, username, account_code ]


http://www.5valleys.com/
http://www.workingwithrails.com/person/8078

<%= text_field_tag :username, params[:username] %>

Here’s the trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/vendor/mysql.rb:566:in
initialize' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/vendor/mysql.rb:566:in new’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/vendor/mysql.rb:566:in
scramble41' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/vendor/mysql.rb:144:in real_connect’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/mysql_adapter.rb:389:in
connect' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/mysql_adapter.rb:152:in initialize’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/mysql_adapter.rb:82:in
new' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/mysql_adapter.rb:82:in mysql_connection’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in
send' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in connection_without_query_cache=’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/query_cache.rb:54:in
connection=' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:230:in retrieve_connection’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in
connection' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/associations.rb:1158:in select_all_rows’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/associations.rb:1015:in
find_with_associations' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/associations.rb:1013:in catch’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/associations.rb:1013:in
find_with_associations' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/base.rb:993:in find_every’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/base.rb:988:in
find_initial' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/base.rb:414:in find’
#{RAILS_ROOT}/app/models/employee.rb:19:in authenticate' #{RAILS_ROOT}/app/controllers/login_controller.rb:10:in login’

Jon G. wrote:

If you can post the stack trace from the error, that’ll help a lot.

One unrelated comment though; you don’t need to separate the different
strings and add them together in your find conditions. Just make it one
string…

[ “employees.deleted_yn = 0 AND employees.username = ? AND
accounts.account_code = ?”, username, account_code ]


http://www.5valleys.com/
http://www.workingwithrails.com/person/8078

Could be a framework mismatch with Rails. I think you see that if you
have Rails <= 1.2.4 and Ruby >= 1.8.6

…and once you upgrade, your conditions can be even nicer:

:conditions=>{:deleted_yn=>false, :username=>username,
:account_code=>account_code}

On Mar 10, 3:04 pm, George P. [email protected]

groan
Yesterday, I spent the day upgrading to Rails 2.0.2. How can I get my
app to point to that instead. I tried changing environments.rb in my
project to version 2.0.2, but that didn’t seem to work…

Jon G. wrote:

AndyV wrote:

Could be a framework mismatch with Rails. I think you see that if you
have Rails <= 1.2.4 and Ruby >= 1.8.6

I agree.


http://www.5valleys.com/
http://www.workingwithrails.com/person/8078

AndyV wrote:

Could be a framework mismatch with Rails. I think you see that if you
have Rails <= 1.2.4 and Ruby >= 1.8.6

I agree.


http://www.5valleys.com/
http://www.workingwithrails.com/person/8078

On 10 Mar 2008, at 20:45, Frederick C. wrote:

On 10 Mar 2008, at 19:04, George P. wrote:

Here’s the trace

The problem is the upgrade to ruby 1.8.6 (which changed some things
in Digest, which is what’s being fiddled with on line 566).
Perhaps the easiest way around this is to use the native mysql
library (which is faster anyway)
Actually, going back through the changelogs I notice that the release
notes for 1.2.3 say ‘1.8.6 compatibility’, so anything prior to that
is probably asking for trouble.
Activerecord 1.5.1 is part of 1.2.1, so you’d want to at least upgrade
to 1.2.3 (which should be painless).

Fred

On 10 Mar 2008, at 19:04, George P. wrote:

Here’s the trace

The problem is the upgrade to ruby 1.8.6 (which changed some things in
Digest, which is what’s being fiddled with on line 566).
Perhaps the easiest way around this is to use the native mysql library
(which is faster anyway)

Fred