app/models/presentation.rb in chili_presentations-0.1.0 vs app/models/presentation.rb in chili_presentations-0.1.1

- old
+ new

@@ -1,16 +1,17 @@ class Presentation < ActiveRecord::Base + UPLOAD_BASE_DIR = File.join(Rails.root, "uploaded_presentations") INDEX_FILENAME = "index.html" UNPACKED_DIRNAME = "unpacked" unloadable validates_presence_of :title has_friendly_id :title, :use_slug => true has_attached_file :contents, - :path => ":rails_root/uploaded_presentations/:attachment/:id_partition/:style/:filename" + :path => "#{UPLOAD_BASE_DIR}/:attachment/:id_partition/:style/:filename" has_attached_file :alternative_format belongs_to :user belongs_to :project @@ -18,20 +19,25 @@ validates_attachment_presence :contents def index_path - File.join(UNPACKED_DIRNAME, INDEX_FILENAME) + File.join(path_without_upload_base_dir, UNPACKED_DIRNAME, INDEX_FILENAME) end - def path_to(some_asset) - some_asset.blank? ? index_path : File.join(UNPACKED_DIRNAME, *some_asset) + def x_accel_redirect_path_to(some_asset) + some_asset.blank? ? index_path : File.join(path_without_upload_base_dir, UNPACKED_DIRNAME, *some_asset) end def permalink friendly_id end def to_s title end + + def path_without_upload_base_dir + File.dirname(contents.path.sub(/#{UPLOAD_BASE_DIR}/, '')) + end + private :path_without_upload_base_dir end