Sha256: e9f1e69e583bcb524a6cb2ec7cc1e3513fc9babc97e8524042540d67bf253e1e
Contents?: true
Size: 1.35 KB
Versions: 3
Compression:
Stored size: 1.35 KB
Contents
module Boxroom class UserFile < ActiveRecord::Base has_attached_file :attachment, :path => ":rails_root/#{Boxroom.configuration.uploads_path}/:rails_env/:id/:style/:id", :restricted_characters => Boxroom::RESTRICTED_CHARACTERS do_not_validate_attachment_file_type :attachment belongs_to :folder has_many :share_links, :dependent => :destroy validates_attachment_presence :attachment, :message => I18n.t(:blank, :scope => [:activerecord, :errors, :messages]) validates_presence_of :folder_id validates_uniqueness_of :attachment_file_name, :scope => 'folder_id', :message => I18n.t(:exists_already, :scope => [:activerecord, :errors, :messages]) validates_format_of :attachment_file_name, :with => /\A[^\/\\\?\*:|"<>]+\z/, :message => I18n.t(:invalid_characters, :scope => [:activerecord, :errors, :messages]) def copy(target_folder) new_file = self.dup new_file.folder = target_folder new_file.save! #TODO: refactor to support S3 path = "#{Rails.root}/#{Boxroom.configuration.uploads_path}/#{Rails.env}/#{new_file.id}/original" FileUtils.mkdir_p path FileUtils.cp_r self.attachment.path, "#{path}/#{new_file.id}" new_file end def move(target_folder) self.folder = target_folder save! end def extension File.extname(attachment_file_name)[1..-1] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
boxroom-0.0.4 | app/models/boxroom/user_file.rb |
boxroom-0.0.3 | app/models/boxroom/user_file.rb |
boxroom-0.0.2 | app/models/boxroom/user_file.rb |