Topic: What breaks find_by?

I am using agile web development with rails and am trying to implement the user authentication code.

Code (table and column names are mine):
if TcEmployee == find_by_loginid(loginid)
  if TcEmployee.hashed_password == encrypt_password........
............

TcEmployee == find_by_loginid(loginid) never finds the employee record even though I know what the correct login id is and verified it with psql, a postgreSQL utility; as well as inserted logger.debug statements into the code which verified the values passed to the routine are what I think they are.

Originally I used 'login' as the column name but in despiration changed it to loginid in case 'login' is a reserved word.

the loginid and password are both 'again' (you can tell I tried this a lot!) so there are no special characters that might break a search.

So what can break find_by_ and keep it from successfully locating a record?

Thanks for any help.  -Fred

Re: What breaks find_by?

if TcEmployee.find_by_loginid(loginid)

it doesn't make any difference AFAIK but the rails way is more like.

Tc_employee.find_by_login_id(login_id)

Using the underscore between every natural word helps reduce the chance of using a reserved word and makes your code more readable.

Re: What breaks find_by?

Your log file is your friend smile
Have a look at the log entries for the action concerned and you will see the SQL statements used and the params passed to the action
If you are not sure how to read the log file then post the entries in here along wiht the controller code

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: What breaks find_by?

I found out what appears to be the answer.  After bracketing "Tc_employee.find_by_loginid(loginid)" with enough  logger.debug statements to fill a bucket, and seeing a log file that seems to be locating the correct record with 'find_by_', I finally realized that the 'case' of the variable 'TcEmployee' must be a problem, so I changed instances of 'TcEmployee' to 'tcEmployee' and the 'find_by_' started working!  I don't remember reading about a variable names 'case' being important but apparently it is and must start with a lower case.

Thanks to everyone that read my post and considered this problem. -Fred

Re: What breaks find_by?

case is important for Rails.
You have to remember that it's *nix (linux, unix)/C++ gurus that wrote ruby.
my_variable =  SomeModel.find(1)
My_variable.something WILL give you an error as My_variable is NOT the same as my_variable

convention sais variables are all lower case separated by _ between words, with class names being camel cased (initial letters of each word being in capitals with no _to separate words.

Glad you found the problem and the next time you find yourself fighting with Rails consider whether or not you are following convention - Probably the best advice you will ever get regarding RoR.

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)