Help with rails active record querying (like clause)

activerecord, ruby-on-rails, ruby-on-rails-3

Solution

This looks like a problem that would be better suited to using search rather than SQL. Have you considered something like thinking sphinx or act as ferret (solr would probably be overkill).

...if you must do this in sql, you could build a query something like this:

cols = ['first_name', 'last_name', 'middle_name']
query = 'John Smith'
sql_query = cols.map{|c| query.split.map{|q| "#{c} like '?'"}}.join(' OR ')
sql_query_array = query.split * cols.count
Student.where(sql_query, sql_query_array)

Problem

I want my code to do two things that is currently not doing ``` @students = Student.where(["first_name = ? OR middle_name = ? OR last_name = ?", params[:query].split]) ``` Work. (it says im supposed to pass 4 parameters but I want the user to be able to type words and find by those words on each of those fields and return whatever matches) Actually use Like clause instead of rigid equal clause. Please Help.

Original source