Thank you very much.
FYI though this could probably be improved this is what I ened up with in
my model
def self.manufacturer_model_contains(query)
query = query.split.map {|term| "%#{term}%" }
sql =
self.includes(:manufacturer).where(Manufacturer.arel_table[:name].matches(query[0]))
sql =
sql.where(MachineModel.arel_table[:model_of_machine].matches(query[1])) if
query[1]
sql
end
Bob
On Wednesday, October 10, 2012 3:36:57 AM UTC-4, Bryan Larsen wrote:
>
> On Tue, Oct 9, 2012 at 3:09 PM, Bob Sleys <[email protected] <javascript:>>
> wrote:
> > Ok getting closer
> >
> > Now I getting the following error
> >
> > undefined method `manufacturer_model_contains' for
> > #<ActiveRecord::Relation:0x00000006c13350>
> >
> >
> > Do I need to add a method to my model to handle it? If so what would it
> > look like. IE is it doing to search for the query string?
>
> That's right. http://cookbook.hobocentral.net/manual/scopes#_contains
>
> You can do it with:
>
> def self.manufacturer_model_contains(query)
>
> self.includes(:manufacturer).where(Manufactuer.arel_table[:name].matches(query))
>
>
> + self.model_of_machine_contains(q)
> end
>
> Note how I'm using AREL for the first clause. That way it will
> automatically switch to ILIKE in postgres.
>
> One thing the above doesn't do is split your query: if the user
> supplies a search for both the model & manufacturer, it will fail.
> This shows how to do that:
>
>
> http://stackoverflow.com/questions/4027276/help-with-rails-active-record-querying-like-clause
>
>
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/hobousers/-/CyoJsDR1oI8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.