app/models/asset.rb
##
# Uploads the file and sets public_url attribute
# to the url of the remote S3 object
#
# === Parameters
#
# [file_path (String)] full path of the file to upload
#
Uploads the file and sets public_url attribute
to the url of the remote S3 object

Parameters

[file_path (String)] full path of the file to upload
Uploads the file and sets public_url attribute to the url of the remote S3 object Parameters [ file_path ( String ) ] full path of the file to upload
def store!
    prefix = "#{Time.now.strftime("%Y%m%d%H%M%S")}"
    fname = prefix+(@file.respond_to?(:original_filename) ? @file.original_filename : File.basename(@file))
    o = s3_bucket.objects["#{asset_path}#{fname}"]
    o.write(Pathname.new(@file.path), {
      acl: :public_read,
      content_type: MIME::Types.type_for(@file.path).first.to_s
    })
    remote_url = o.public_url.to_s
    self.set(public_url: remote_url)
    self.this.update(public_url: remote_url)
  end
def store! prefix = "#{Time.now.strftime("%Y%m%d%H%M%S")}" fname = prefix + ( @file . respond_to? ( :original_filename ) ? @file . original_filename : File . basename ( @file ) ) o = s3_bucket . objects [ "#{asset_path}#{fname}" ] o . write ( Pathname . new ( @file . path ) , { acl : :public_read , content_type : MIME :: Types . type_for ( @file . path ) . first . to_s } ) remote_url = o . public_url . to_s self . set ( public_url : remote_url ) self . this . update ( public_url : remote_url ) end
Uploads the file and sets public_url attribute
to the url of the remote S3 object
Uploads the file and sets public_url attribute to the url of the remote S3 object
# Upload the file # Set the public_url attribute