Skip to content

Commit

Permalink
Removed target folder check for copy/move and changed path were files…
Browse files Browse the repository at this point in the history
… are stored.
  • Loading branch information
mischa78 committed May 12, 2011
1 parent 3db7ac9 commit 2b827a5
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions app/models/user_file.rb
@@ -1,5 +1,5 @@
class UserFile < ActiveRecord::Base
has_attached_file :attachment, :path => ':rails_root/uploads/:id/:style/:id'
has_attached_file :attachment, :path => ':rails_root/uploads/:rails_env/:id/:style/:id'

belongs_to :folder

Expand All @@ -8,19 +8,16 @@ class UserFile < ActiveRecord::Base
validates_format_of :attachment_file_name, :with => /^[^\/\\\?\*:|"<>]+$/, :message => I18n.t(:invalid_characters, :scope => [:activerecord, :errors, :messages])

def copy(target_folder)
Folder.check_target_folder(target_folder)

new_file = self.clone
new_file.folder = target_folder
new_file.save!

path = "#{Rails.root}/uploads/#{new_file.id}/original"
path = "#{Rails.root}/uploads/#{Rails.env}/#{new_file.id}/original"
FileUtils.mkdir_p path
FileUtils.cp_r self.attachment.path, "#{path}/#{new_file.id}"
end

def move(target_folder)
Folder.check_target_folder(target_folder)
self.folder = target_folder
save!
end
Expand Down

0 comments on commit 2b827a5

Please sign in to comment.