Skip to content

Instantly share code, notes, and snippets.

@freshfey
Created July 24, 2012 08:11
Show Gist options
  • Save freshfey/3168759 to your computer and use it in GitHub Desktop.
Save freshfey/3168759 to your computer and use it in GitHub Desktop.
Song Model
class Song < ActiveRecord::Base
belongs_to :user
acts_as_voteable
has_attached_file :music, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml"
validates_attachment_content_type :music, :content_type => ['application/mp3', 'application/x-mp3', 'audio/mpeg', 'audio/mp3' ],
:message => 'file must be of filetype .mp3!'
validates_attachment_size :music, :less_than => 10.megabytes
def previous_song
self.class.first(:conditions => ["created_at < ?", created_at], :order => "created_at desc")
end
def next_song
self.class.first(:conditions => ["created_at > ?", created_at], :order => "created_at asc")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment