Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
search query question
Sam Ginko
6/26/2008 1:22:00 PM
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
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
search query question
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password