Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get either true or false on a database find in Rails?

How do I get either true or false on a database find in Rails?

Say if I have a database with username field and a password field. I want to find a certain username in my database and return true if I found it or false if I didn't. I'm a noob and I tried googling it but could not find anything.

ex.

q = User.new
q.username = "Joe"
q.password = "password"

User.find_by_username("Joe") -> true
User.find_by_username("Admin") -> false

Thanks for the help.

like image 485
nariel0822 Avatar asked Dec 17 '22 12:12

nariel0822


1 Answers

User.exists?(:username => "Joe")
like image 63
Wizard of Ogz Avatar answered Jan 10 '23 23:01

Wizard of Ogz