title: Rails carrierwave manual file "upload" wrong url
body: <p>Schema:</p>
  
  <pre><code>  create_table "playlists", force: true do |t|
      t.string   "name",                                 null: false
      t.text     "description",             default: "", null: false
      t.datetime "created_at",                           null: false
      t.datetime "updated_at",                           null: false
      t.string   "file",        limit: 256, default: "", null: false
    end
  
    create_table "devices", force: true do |t|
      t.string   "login"
      t.string   "name"
      t.datetime "created_at",                 null: false
      t.datetime "updated_at",                 null: false
      t.integer  "playlist_id"
      t.string   "serial_number", default: "", null: false
    end
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>class Playlist &lt; ActiveRecord::Base
    has_many :media_deployments 
    has_many :media_items, :through =&gt; :media_deployments
    has_many :devices
  
    after_save :playlist_updated
    before_save :create_playlist_file
  
    mount_uploader :file, PlaylistFileUploader
  
    private
      def create_playlist_file
        if !media_items.empty?
          tempfile = Tempfile.new(['playlist', '.m3u'])
          self.media_deployments.order(:playlist_position).each do |deployment|
            tempfile.puts deployment.media_item.file_identifier
          end
          tempfile.close
          self.file = tempfile
          tempfile.unlink
        end
      end
  
      def playlist_updated
        self.devices.each do |d|
      puts "******************\n\n"
      puts "playlist by device: " + d.playlist.inspect + " url " + d.playlist.file_url + " new_record?" + d.playlist.new_record?.to_s
      pp = Playlist.where("device_id" == d.id).first
      puts "playlist found: " + pp.inspect + " url " + pp.file_url + " new_record?" + pp.new_record?.to_s
      puts "******************\n\n"
        end
     end
  end
  </code></pre>
  
  <p>Uploader:</p>
  
  <pre><code>class PlaylistFileUploader &lt; CarrierWave::Uploader::Base
    include CarrierWave::MimeTypes
    process :set_content_type
    def store_dir
      "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
    def extension_white_list
      %w(m3u)
    end
    def filename
      "playlist.m3u" if original_filename
    end
  end
  </code></pre>
  
  <p>So, whenever a playlist object updated m3u file gets created and attached to it.
  The problem is here:</p>
  
  <pre><code>******************
  playlist by device: #&lt;Playlist id: 15, name: "test1", description: "", created_at: "2014-10-21 04:12:20", updated_at: "2014-11-14 04:55:16", file: "playlist.m3u"&gt; url /uploads/tmp/1415940916-15072-1149/playlist20141114-15072-1066hu7.m3u new_record?false
    CACHE (0.0ms)  SELECT  "playlists".* FROM "playlists"  ORDER BY "playlists"."id" ASC LIMIT 1
  playlist found: #&lt;Playlist id: 15, name: "test1", description: "", created_at: "2014-10-21 04:12:20", updated_at: "2014-11-14 04:55:16", file: "playlist.m3u"&gt; url /uploads/playlist/file/15/playlist.m3u new_record?false
  ******************
  </code></pre>
  
  <p>When I loop through devices I get the playlist with wrong file url. When I select the playlist manually it returns the same exact playlist object but with correct file url.</p>