Forum: Ruby on Rails Searching within active record results - ror n00b

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jake S. (Guest)
on 2006-02-23 23:03
(Received via mailing list)
I am trying to set up a search page that looks within a product catalog.

There are several many to many relationships with the items object.

I am trying to be able to narrow searchs and then allow for text
using tsearch2 and postgres.

@format = Format.find(@params[:format_id])
@items = @format.items

And then do a find_by_sql on the @items, but I know this isnt how you do
@items.find_by_sql("SELECT * FROM items WHERE idxfti @@
to_tsquery('default', '#{@str}')

class Format < ActiveRecord::Base

    has_and_belongs_to_many :items

    belongs_to     :parent,
                :class_name => "Category",
                :foreign_key => "parent_id"

    has_many    :children,
                :class_name => "Category",
                :foreign_key => "parent_id",
                :order => "title",
                :dependent => true

    validates_presence_of :title


class Item < ActiveRecord::Base

    has_and_belongs_to_many :formats
    has_and_belongs_to_many    :keywords
    has_and_belongs_to_many    :images

    has_many                :reviews


Thanks for any pointers
This topic is locked and can not be replied to.