On Tue, Oct 9, 2012 at 3:09 PM, Bob Sleys <[email protected]> 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 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.

Reply via email to