Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created March 17, 2013 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemcalilly/0ccd29f234f6722311a0 to your computer and use it in GitHub Desktop.
Save leemcalilly/0ccd29f234f6722311a0 to your computer and use it in GitHub Desktop.
class Song < ActiveRecord::Base
attr_accessible :artist, :artwork, :category, :credits, :tag_list, :title, :track, :year
belongs_to :user
has_many :albumizations
has_many :albums, :through => :albumizations
validates_presence_of :user_id
validates_presence_of :title
acts_as_taggable
mount_uploader :track, TrackUploader
after_save :enqueue_track
def track_name
File.basename(track.path || track.filename) if track
end
def enqueue_track
TrackWorker.perform_async(id, key) if key.present?
end
class TrackWorker
include Sidekiq::Worker
def perform(id, key)
song = Song.find(id)
song.key = key
song.remote_track_url = song.track.direct_fog_url(with_path: true)
song.save!
song.update_column(:track_processed, true)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment