Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Playing with examples to come up with a good API.

git-svn-id: https://dwerg.net/svn/attachment-san@6 fb193781-c870-48b2-bb2a-80db8c48ce66
  • Loading branch information...
commit fcfbd847fc345a11d33ea71b4bcdc96c9bc87212 1 parent 8b87dea
manfred authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 examples/photo.rb
View
38 examples/photo.rb
@@ -1,3 +1,41 @@
class Photo < ActiveRecord::Base
attachment_san :allows => Mime::JPG
+ after_upload :make_black
+
+ has_one :thumbnail, :class => 'Photo'
+ belongs_to :large_photo, :class => 'Photo'
+ before_create :do_create_thumbnail
+
+ def do_create_thumbnail
+ unless large_photo
+ create_thumbnail :uploaded_data = uploaded_data, :size => "<300x400"
+ end
+ end
+end
+
+# ---
+
+class Photo < ActiveRecord::Base
+ has_one :thumbnail
+ has_one :full_size
+
+ def uploaded_data=(data)
+ build_thumbnail :uploaded_data => data
+ build_full_size :uploaded_data => data
+ end
+end
+
+class Attachment < ActiveRecord::Base
+end
+
+class Thumbnail < Attachment
+ attachment_san :resizes_to => "<300x400"
+
+ def resize(image)
+ attachment.resize(image)
+ end
+end
+
+class FullSize < Attachment
+ attachment_san :resizes_to => "<600x800"
end
Please sign in to comment.
Something went wrong with that request. Please try again.