Created
August 26, 2013 20:11
-
-
Save jgrannas/6346071 to your computer and use it in GitHub Desktop.
Timeslip - trying to limit method to one timeslip per car
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 characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment