So i''ve been reading acts_as_ferret for about 3 days now and still have not figured out how to create one search over all my models. that way when people search my site, they can actually find what they''re looking for, and not just one model at a time. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jon,
> not figured out how to create one search over all my models.
It''s not that hard to write :
results = Book.find_by_contents(query) + Disk.find_by_contents(query)
If you really have loads of models to search through, you could write
something like (untested) :
MODELS=%w(Book Disk Person Animal Article Page Concert Joke Story)
results = MODELS.collect{|klass|
klass.constantize.find_by_contents(query)
}.flatten
Alain
----
blog.ravet.com
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
D. Taylor Singletary
2007-May-09 22:58 UTC
Re: Acts_as_ferret; one search over multiple models??
You could also always make a model that covers them all through
methods, using the ability to point acts as ferret at other fields.
Example:
class Order < ActiveRecord::Base # ( or not even maybe.. )
belongs_to :reservation
belongs_to :customer
acts_as_ferret :remote => true, :additional_fields => [
:reservation_to_s, :customer_to_s ]
def reservation_to_s
self.reservation.to_s # assuming you defined it
end
def customer_to_s
self.customer.to_s # ditto
end
end
Just one option... of many.
D. Taylor Singletary,
Reality Technicians
http://www.realitytechnicians.com
On 5/9/07, Alain Ravet
<alain.ravet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Jon,
>
>
> > not figured out how to create one search over all my models.
>
> It''s not that hard to write :
> results = Book.find_by_contents(query) + Disk.find_by_contents(query)
>
>
> If you really have loads of models to search through, you could write
> something like (untested) :
>
> MODELS=%w(Book Disk Person Animal Article Page Concert Joke Story)
> results = MODELS.collect{|klass|
> klass.constantize.find_by_contents(query)
> }.flatten
>
>
> Alain
> ----
> blog.ravet.com
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-10 00:04 UTC
Re: Acts_as_ferret; one search over multiple models??
On May 9, 9:05 am, Jon Druse <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> So i''ve been reading acts_as_ferret for about 3 days now and still have > not figured out how to create one search over all my models. that way > when people search my site, they can actually find what they''re looking > for, and not just one model at a time. > > -- > Posted viahttp://www.ruby-forum.com/.Look at multisearch http://rubyforge.org/pipermail/ferret-talk/2007-May/003275.html http://projects.jkraemer.net/acts_as_ferret/rdoc/classes/ActsAsFerret/ClassMethods.html#M000014 or combine searches over individual models http://infovore.org/archives/2006/09/22/cross-model-searching-in-rails-with-ferret/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---