Skip to content

Instantly share code, notes, and snippets.

@jforaker
Created October 23, 2013 16:58
Show Gist options
  • Save jforaker/7122379 to your computer and use it in GitHub Desktop.
Save jforaker/7122379 to your computer and use it in GitHub Desktop.
class Story < ActiveRecord::Base
validates :title, :link, :category, :upvotes, presence: true
scope :popular, -> { where('upvotes >= ?', 4)}
scope :recent, -> { where('created_at >= ?', Date.today)}
def self.search_for(query)
where('title LIKE :query OR category LIKE :query', query: "%#{query}%")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment