[Ferret-talk] search two related tables

Katsuo Isono comics at bigpond.net.au
Fri Apr 18 07:25:49 EDT 2008


Hi, It would be trulely appreciated if anyone can give me some advise on
this.
I have two related tables titles and authors. Using acts_as_ferret, I
can search by title name. However, when search by author name or ausname
in this case, I only get "sorry, found 0 item".

class Title < ActiveRecord::Base
  acts_as_ferret :additional_fields => [:author_name]
  belongs_to :author

  def author_name
    return author.ausname
  end
-------------------------
class Author < ActiveRecord::Base
  has_many :titles
end
-------------------------
def search
    if params[:q]
      query = params[:q]
      @titles = Title.find_by_contents(query)
      unless @titles.size > 0
     flash.now[:notice_not_found] = "Sorry, found 0 item"
    end
    render :action => 'search_result'
    end
end
-- 
Posted via http://www.ruby-forum.com/.


More information about the Ferret-talk mailing list