Save track files in new Sound model:
* Consolidate migrations * Add Sound model. Each sound can belong to a track and contains informations about one sound file.
This commit is contained in:
18
app/models/sound.rb
Normal file
18
app/models/sound.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
require 'fileutils'
|
||||
|
||||
class Sound < ActiveRecord::Base
|
||||
belongs_to :track
|
||||
|
||||
validates_presence_of :sha256
|
||||
validates_presence_of :mime_type
|
||||
|
||||
def path
|
||||
"#{Rails.root}/data/sounds/#{sha256}"
|
||||
end
|
||||
|
||||
def file=(file)
|
||||
self.sha256 = Digest::SHA256.file(file.path).hexdigest
|
||||
FileUtils.cp file.path, path
|
||||
self.mime_type = file.content_type
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user