Datamapper + Carrierwave storage method is not called, only the cache

I have a really simple sinatra app that uses datamapper and carrier.

I reduced the bootloader to a minimum:

class PhotoUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  storage :file
end

      

And use one simple model:

class Photo
  include DataMapper::Resource

  property :id, Serial
  property :caption, String
  property :position, Integer
  property :created_at, DateTime
  property :updated_at, DateTime

  mount_uploader :source, PhotoUploader

  belongs_to :album
end

      

It happens that when I use it:

post '/admin/album/:id/photo/create' do
  album = Album.get(params[:id])
  photo = Photo.create(params[:photo])
  album.photos << photo
  album.save!

  redirect '/admin/album'
end

      

photo

is usually created in the database, and the file is usually loaded into the cache directory but not moved to its final destination.

I got the carrier code and could check that the method cache!

is being called, but not the method store!

.

I tried using a loader without any linkage to the object:

get '/lorem' do
  f = File.open('test.png')
  u = PhotoUploader.new
  u.store!(f)

  "ok"
end

      

In this case, everything works as expected.



===================== UPDATE ==========================

I believe I have found the source of the problem. While running the debugger, I realized:

gems/dm-core-1.2.0/lib/dm-core/query.rb:1014
conditions.each do |condition|
(rdb:1) 
gems/carrierwave-0.6.2/lib/carrierwave/sanitized_file.rb:290
def sanitize(name)
(rdb:4) 
gems/carrierwave-0.6.2/lib/carrierwave/sanitized_file.rb:299
def split_extension(filename)
(rdb:4) 
gems/carrierwave-0.6.2/lib/carrierwave/sanitized_file.rb:29
self.file = file
(rdb:4) 
gems/carrierwave-0.6.2/lib/carrierwave/sanitized_file.rb:269
if file.is_a?(Hash)
(rdb:4) 
gems/carrierwave-0.6.2/lib/carrierwave/sanitized_file.rb:274
@file = file

(rdb:4) pp file
"/Users/jvalente/Projects/dummy/public/uploads/{:filename=>\"Screen Shot 2013-01-24 at 4.57.15 PM.png\", :type=>\"image/png\", :name=>\"photo[source]\", :tempfile=>#<File:/var/folders/jp/wm1gxk8558d36rh9vzkmx4jw0000gn/T/RackMultipart20130128-27245-105ybbf>, :head=>\"Content-Disposition: form-data; name=\\\"photo[source]\\\"; filename=\\\"Screen Shot 2013-01-24 at 4.57.15 PM.png\\\"\\r\\nContent-Type: image/png\\r\\n\"}"

      

This is clearly not true, as it will fail to fulfill the condition file.is_a?(Hash)

and enter:

@file = file
@original_filename = nil
@content_type = nil

      

However, I cannot figure out why this is happening.

+3


source to share





All Articles