<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -14,11 +14,12 @@ module Ketlai
         def belongs_to_image(association_id, options = {})
           belongs_to association_id, options
           define_method(&quot;#{association_id}=&quot;) do |value|
-            return if value.blank?
+            this_file = file_value(value)
+            return if this_file.blank?
             association = self.class.reflect_on_association(association_id)
-            if value.is_a?(StringIO) or (defined?(ActionController) and value.is_a?(ActionController::UploadedTempfile))
+            if this_file.is_a?(StringIO) or (defined?(ActionController) and this_file.is_a?(ActionController::UploadedTempfile))
               image_class = association.class_name.constantize
-              value = image_class.create!(:uploaded_data =&gt; value)
+              value = image_class.create!(:uploaded_data =&gt; this_file)
             end
             write_attribute association.association_foreign_key, value.id
           end
@@ -36,21 +37,28 @@ module Ketlai
         
         protected
           
+          def file_value(data)
+            data.is_a?(Hash) ? data['uploaded_data'] : data
+          end
+          
           def define_has_one_method(association_id)
             define_method(&quot;#{association_id}=&quot;) do |data|
-              return unless valid_file?(data)
+              this_file = file_value(data)
+              return unless valid_file?(this_file)
               association = self.class.reflect_on_association(association_id)
-              self.send(&quot;build_#{association_id}&quot;, :uploaded_data =&gt; data)
+              self.send(&quot;build_#{association_id}&quot;, :uploaded_data =&gt; this_file)
             end
           end
           
           def define_has_many_method(association_id)
             define_method(&quot;#{association_id}=&quot;) do |data|
-              return if data.empty? or data[0].blank?
+              return if data.empty? or (data[0].respond_to?(:blank?) and data[0].blank?) or (data[0].is_a?(Hash) and data[0]['uploaded_data'].blank?)
               association = self.class.reflect_on_association(association_id)
               data.each do |value|
-                if valid_file?(value)
-                  self.send(association_id).build(:uploaded_data =&gt; value)
+                this_file = file_value(value)
+                
+                if valid_file?(this_file)
+                  self.send(association_id).build(:uploaded_data =&gt; this_file)
                 end
               end
             end</diff>
      <filename>lib/image_associations.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>50ca6b0ff5c3951c9042091eedb326edbf04ff14</id>
    </parent>
  </parents>
  <author>
    <name>James Stewart</name>
    <email>james@jystewart.net</email>
  </author>
  <url>http://github.com/jystewart/image-associations/commit/1a9be06effa003da29481929c7ce1211f4cc012f</url>
  <id>1a9be06effa003da29481929c7ce1211f4cc012f</id>
  <committed-date>2008-11-11T07:45:59-08:00</committed-date>
  <authored-date>2008-11-11T07:45:59-08:00</authored-date>
  <message>Make methods more flexible so they either take a file directly or a hash with a key of uploaded_data</message>
  <tree>b3d9179484545e334236c9d78f921ad9ab6b0c25</tree>
  <committer>
    <name>James Stewart</name>
    <email>james@jystewart.net</email>
  </committer>
</commit>
