3 ways to find with Rails
Searching for data in a database is the best and easiest part of a rails app! I have come up with a list below of three ways to get the job done. Use any of the three and you will be very happy with your results!
One of the design principles of Rails is providing a layer of high-level function for many common tasks, while still leaving open a window to the layers underneath.
1) For example, in order to find a user by screen name and password, Rails creates a function called:
[ruby]User.find_by_screen_name_and_password(screen_name,password)[/ruby]
2) Now we will go one layer down:
[ruby]User.find(
:all,
:conditions => “password=’#{password}%’”,
rder => “id”
)[/ruby]
3) Now lets give it a raw SQL statement:
[ruby]User.find_by_sql(“SELECT * FROM `table_name` ORDER BY id DESC”)[/ruby]


