Hi all,
Haven’t played with rails for a while so I’m a little stuck. I’ve got to
make a search functionality across models.
Let me try to explain this (sorry for lack of clarity, I’ve been reading
so many search gems etc that I’m a little fuzzy now):
- Stores have town and county fields
- Stores has_many Products which each have their own name and level
Users need to be able to find all Stores (possibily limited by town or
county) which have one or more Products identified by name AND a minimum
level.
So I might search for Stores which have the Product ‘Small Wooden Table’
with a level of at least 4 AND have the Product ‘Oak Table’ at least
level 10. Then I might restrict that to Stores in the county of
‘Yorkshire’.
The list of Products is pretty long (300+) and I don’t think it would be
user friendly to put them in a long drop-down list, so I’m tempted to
let users type in the name and level manually. If they don’t type the
name correctly, then I guess they won’t get the right results.
I’ve looked at several gems (including searchlogic and ransack) but none
seem to give me the ability to search related models in this way. I
might have to knock together something from scratch but I don’t want to
end up being hideously inefficient.
Grateful for any pointers on this, and please let me know if I haven’t
explained it well enough. I should add that I might be tempted to use
some sort of ajax for this (maybe for adding new product fields to the
form, or for autocomplete) but since my days with rails 2.x, ajax seems
to have gotten a lot more complicated to use.
Many thanks