Navigation Menu

Skip to content

Commit

Permalink
Add S3 storage samples files
Browse files Browse the repository at this point in the history
  • Loading branch information
galetahub committed Mar 1, 2010
1 parent 14c753d commit 49eebb5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/s3/attachment_file.rb
@@ -0,0 +1,23 @@
class AttachmentFile < Asset

# === List of columns ===
# id : integer
# data_file_name : string
# data_content_type : string
# data_file_size : integer
# assetable_id : integer
# assetable_type : string
# type : string
# locale : integer
# user_id : integer
# created_at : datetime
# updated_at : datetime
# =======================

has_attached_file :data,
:s3_credentials => "#{Rails.root}/config/s3.yml", :bucket => "yourbucket",
:storage => :s3,
:path => "#{APP_NAME}/files/:id/:filename"

validates_attachment_size :data, :less_than => 10.megabytes
end
41 changes: 41 additions & 0 deletions examples/s3/picture.rb
@@ -0,0 +1,41 @@
class Picture < Asset

# === List of columns ===
# id : integer
# data_file_name : string
# data_content_type : string
# data_file_size : integer
# assetable_id : integer
# assetable_type : string
# type : string
# locale : integer
# user_id : integer
# created_at : datetime
# updated_at : datetime
# =======================



has_attached_file :data,
:s3_credentials => "#{Rails.root}/config/s3.yml", :bucket => "yourbucket",
:storage => :s3,
:path => "#{APP_NAME}/images/:id/:style_:basename.:extension",
:styles => { :content => '575>', :thumb => '100x100' }

validates_attachment_size :data, :less_than=>2.megabytes

def url_content
url(:content)
end

def url_thumb
url(:thumb)
end

def to_json(options = {})
options[:methods] ||= []
options[:methods] << :url_content
options[:methods] << :url_thumb
super options
end
end
2 changes: 2 additions & 0 deletions examples/s3/s3.yml
@@ -0,0 +1,2 @@
access_key_id: "YOUR KEY ID"
secret_access_key: "YOUR SECRET KEY"

0 comments on commit 49eebb5

Please sign in to comment.