Skip to content

Instantly share code, notes, and snippets.

@kibaekr
Created June 26, 2012 08:07
Show Gist options
  • Save kibaekr/2994293 to your computer and use it in GitHub Desktop.
Save kibaekr/2994293 to your computer and use it in GitHub Desktop.
Model Code for Track (post)
class Track < ActiveRecord::Base
acts_as_taggable
include PgSearch
pg_search_scope :search_by_title, :against => :title #:using => [:tsearch => {:prefix => true}], #:trigram, :dmetaphone]
pg_search_scope :search_by_weight,
:against => {
:title => 'B',
:description => 'C'
},
:associated_against => {
:tags => [:name]
},
:using => [:tsearch] #, :trigram, :dmetaphone]
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
has_many :track_users
has_many :users, :through => :track_users
# attr_accessible :title, :category, :difficulty, :description, :missions_attributes, :author_id
has_many :missions, :order => "position ASC", :dependent => :destroy
accepts_nested_attributes_for :missions, :allow_destroy => true
has_many :track_comments, :dependent => :destroy
mount_uploader :image, TrackImageUploader
acts_as_voteable
#validates :author_id, :presence => true
#validates :title, :presence => true
#validates :description, :presence => true
#validates :difficulty, :presence => true
#validates :intendedtime, :presence => true
DIFFICULTIES = ['Beginner', 'Medium', 'Advanced']
CATEGORIES = ['Technology and Internet', 'Creative Arts and Music', 'Academics and Test Prep', 'Business and Professional', 'Sports and Health', 'Language', 'Game', 'Lifestyle', 'Other']
SORT = ['Top','Recent']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment