> Hello Everybody,
> I am have an advance search form in which i have a field called :name
> in which user can enter 1 or multiple words.
> When there is more than 1 word, i am splitting that string and
> collecting it in to an array.
>
> @collect = Array.new
> @collect << name.split( )
>
> this gives me an array ["John", "whatever",
"anyother"]
> how can i find each item in the array in my rails app?
This isn''t specific enough to know for sure what you want, but
I''m going to assume that you want to search a specific model on a
specific field for each of those terms... if it was me, I would do it like this.
Assume a model of Widget that has a ''title'' string field...
# in my controller action...
# with params[:name] being passed in via the form...
def search
@widgets = Widget.all(:conditions => ["title IN (?)",
params[:name].split(/[ ,]/)])
end
That would let you type in "John, whatever anyother" and have it work
both on spaces and commas. It''s not very efficient though as
it''s an *exact* match so If you have a widget named
''Jon'' it won''t find it.
You may want to look into sphinx or whatever full text search options your
database provides...
-philip
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.