Created
August 26, 2013 20:11
-
-
Save jgrannas/6346071 to your computer and use it in GitHub Desktop.
Revisions
-
jgrannas created this gist
Aug 26, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ class Timeslip < ActiveRecord::Base belongs_to :car belongs_to :user has_one :car_model, through: :car has_one :transmission, through: :car has_one :engine, through: :car default_scope order('et1320 ASC') def youtube_id regex = /^(?:http:\/\/)?(?:www\.)?\w*\.\w*\/(?:watch\?v=)?((?:p\/)?[\w\-]+)/ video_url.match(regex)[1] end def self.by_carmodel(carmodel) scoped = joins(:car_model).where(:car_models => {:name => carmodel}) scoped end def self.by_trans(trans) scoped = joins(:transmission).where(:transmissions => {:name => trans}) scoped end def self.one_per_car scoped = unscoped.select("car_id").group("car_id") scoped end end