title: Saving generated Image with Carrierwave - no form, all inside the model
body: <p>this is a tricky one, I hope someone can help me.</p>
  
  <p>I have a article_set, which has many set_items, each set item has an image.
  I want to create an collage of the images, so one image out of many, and save it with carrierwave.</p>
  
  <p>that's whats going on in my model:</p>
  
  <pre><code>require 'RMagick'
  
  class ArticleSet &lt; ActiveRecord::Base
  
      # ...
  
      after_create :create_collage  
      mount_uploader :blog_image, BlogImageUploader
  
      def create_collage
        # load the template
        template = Magick::Image.read("#{RAILS_ROOT}/public/images/set_template.png").first
  
        # go through all set items by z_index and add lay it over the template
        for item in self.set_items
          photo = Magick::Image.read(item.product.assets.first.image.url(:thumb).to_s).first
          photo.scale(item.width, item.height)
          # composite item over template offsetting pos_x and pos_y for the template border
          template.composite!(photo, item.pos_x, item.pos_y, Magick::OverCompositeOp)
        end
  
        # save composite image to JPG
        template.write("set_#{self.id}_#{Time.now.to_i}.jpg")
  
        #save and upload to s3
  
        self.blog_image.store!(template)
        self.blog_image = self.blog_image.store_path
        self.write_carrierwave_identifier
        self.save  
  
      end
  
  end
  </code></pre>
  
  <p>So far, so good. I can save the set and it runs though this method, but I guess the last part</p>
  
  <pre><code>       #save and upload to s3
  
        self.blog_image.store!(template)
        self.blog_image = self.blog_image.store_path
        self.write_carrierwave_identifier
        self.save  
  </code></pre>
  
  <p>is probably incorrect, in my database I get only NULL values for blog_image.
  It should, of course, contain the file name of the generated file...
  any help highly appreciated.</p>
  
  <p>thanks</p>