I have User model and I have following in the User model
def name
last_name.blank? ? first_name : "#{first_name} #{last_name}"
end
How can I add a find_by_name function to the User model so that I can do this:
User.find_by_name("Peter Smith")
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you can do that using
named_scopeJim and NAD answers for this similar question Rails virtual attribute search or sql combined column search are probably a good start.