Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
How to Use "Like" operation in Active record
4 Posts
How to Use "Like" operation in Active record

Hi

I am trying to put an search option .... but when i try to search for database by

@get_user=User.find(:all, :conditions => ["name like ?",params[:name]+"%"])

My intesion is to find the user whose user name has a perticular string anyware in his name

thank you

Person
r99
Sign In To Rate Post

Hi,

You need a '%' at both ends of the search string.

@user = User.find(:all, :conditions => [“name like ?”, "%#{params[:name]}%“])

:conditions => ['name like ?', '%%' + params[:name] + '%%']

thank you for instantanious responce..

in my case im using Jon's syntax is working ...

im getting error with James's syntax... it is giving CAN'T CONVERT HASH WITH DIFFERENT ACCESS INTO STRING..

Thanks to both of you regards -rasheeed

Person
r99
Sign In To Rate Post
4 Posts
Login to add your message