George Pasley wrote:
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 %>
<table>
<tr>
<td colspan="2"><font size = "4"><b>Sign-in to
BancOffice</b></font></td>
</tr>
<tr>
<td>Company Code:</td>
<td><%= text_field_tag :account_code, params[:account_code] %></td>
</tr>
<tr>
<td>User name:</td>
<td><%= text_field_tag :username, params[:username] %></td>
</tr>
<tr>
<td>Password:</td>
<td><%= password_field_tag :password, params[:password] %></td>
</tr>
<tr>
<td></td>
<td><%= submit_tag "Login" %> </td>
</tr>
</table>
<% 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] = "<font color='red'>Invalid user/password
combination</font>"
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
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 ]