Permalink
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...
manfred
manfred committed Feb 21, 2008
1 parent 8b87dea commit fcfbd847fc345a11d33ea71b4bcdc96c9bc87212
Showing with 38 additions and 0 deletions.
  1. +38 −0 examples/photo.rb
View
@@ -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

0 comments on commit fcfbd84

Please sign in to comment.