Module: Cms::S3::ContentController
- Defined in:
- lib/bcms_s3/s3_module.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(controller_class) ⇒ Object
11 12 13 14 |
# File 'lib/bcms_s3/s3_module.rb', line 11 def self.included(controller_class) controller_class.alias_method_chain :render_page_with_caching, :s3 controller_class.alias_method_chain :try_to_stream_file, :s3 end |
Instance Method Details
#render_page_with_caching_with_s3 ⇒ Object
15 16 17 18 |
# File 'lib/bcms_s3/s3_module.rb', line 15 def render_page_with_caching_with_s3 render_page response.headers['Cache-Control'] = 'public, max-age=300' if Cms::S3.heroku_caching end |
#try_to_stream_file_with_s3 ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bcms_s3/s3_module.rb', line 19 def try_to_stream_file_with_s3 split = @paths.last.to_s.split('.') ext = split.size > 1 ? split.last.to_s.downcase : nil #Only try to stream cache file if it has an extension unless ext.blank? #Check access to file @attachment = ::Attachment.find_live_by_file_path(@path) if @attachment raise Cms::Errors::AccessDenied unless current_user.able_to_view?(@attachment) if Cms::S3.enabled #get the file off S3 redirect_to("http://#{Cms::S3.[:bucket]}.s3.amazonaws.com/#{@attachment.file_location}") else #Construct a path to where this file would be if it were cached @file = @attachment.full_file_location #Stream the file if it exists if @path != "/" && File.exists?(@file) send_file(@file, :filename => @attachment.file_name, :type => @attachment.file_type, :disposition => "inline" ) end end end end end |