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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0adaf2b0bb8e54b9c42992bd2c1d452b?d=identicon&s=25 Jake Smith (Guest)
on 2006-02-23 22: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
searches
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
this.
@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

end



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

end

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