search query question

S

Sam Ginko

I'm not using ferret because the search I need is not that complicated.
I created a basic active record search. I'm using some code from the
pragmaticprogrammer book. This is the issue:

I can get the single keyword to work fine when entered into the search
box, but when you put to keywords separated by a space the search
returns no results. It makes sense since the function below was
structured for a single key search. So I tried to modify it by getting
the string, splitting it and trying to do a loop for the newly splitted
string. Here is when I get the error "can't convert Array into String".
I'm sure that I'm doing some logical mistakes but I'm new to ruby on
rails so please forgive me.

hope some one can help

def conditions_by_like(value, *columns)

myArray = value.gsub(/[^\A-Za-z0-9\s]/, "").split(/ /)
myArray.each do |itemz|
columns = self.user_columns if columns.size==0
columns = columns[0] if columns[0].kind_of?(Array)
conditions = columns.map { |c|
c = c.name if c.kind_of? ActiveRecord::ConnectionAdapters::Column
"`#{c}` LIKE " +
ActiveRecord::Base.connection.quote("%#{itemz}%")
}.join(" OR ")
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top