Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AndyMoreland/102191 to your computer and use it in GitHub Desktop.
Save AndyMoreland/102191 to your computer and use it in GitHub Desktop.
### In main model
# for each Beer object, there are some number 0-50 individual review objects, listed
# in the Tastes model
# For my "beer list" in my view, i need to search the child reviews, looking for particular
# phrases and return the results
#
# Any suggestions?
###
class Beer < ActiveRecord::Base
belongs_to :brewery, :counter_cache => true
belongs_to :container
belongs_to :style
has_many :tastes
cattr_reader :per_page
@@per_page = 50
def self.tastes_search
return nil if q.nil? or q==""
default_options = {:limit => 24, :page => 1}
options = default_options.merge options
# get the offset based on what page we're on
options[:offset] = options[:limit] * (options.delete(:page).to_i-1)
# now do the query with our options
results = Taste.find_by_contents(q, options)
return [results.total_hits, results]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment