meskyanichi/mongoid-paperclip — Issue #17: Everything gets /assets/original/missing.png
Author: hackeron
Created: 2011-11-20 21:40:38+00:00
State: open

This is in my models file:
```
has_mongoid_attached_file :asset,
:styles => { :small => ['36x36#', :jpg],
:medium => ['72x72#', :jpg],
:large => ['115x115#', :jpg] },
:url => '/:class/:id/:style.:extension',
:path => ':rails_root/public/uploads/:id_partition/:style.:extension',
:processors => lambda { |a| a.video? ? [ :video_thumbnail ] : [ :thumbnail ] }
```

This is my processor:
```
module Paperclip
class VideoThumbnail < Processor

attr_accessor :time_offset, :geometry, :whiny

def initialize(file, options = {}, attachment = nil)
super
@time_offset = options[:time_offset] || '-4'
unless options[:geometry].nil? || (@geometry = Geometry.parse(options[:geometry])).nil?
@geometry.width = (@geometry.width / 2.0).floor * 2.0
@geometry.height = (@geometry.height / 2.0).floor * 2.0
@geometry.modifier = ''
end
@whiny = options[:whiny].nil? ? true : options[:whiny]
@basename = File.basename(file.path, File.extname(file.path))
end

def make
dst = Tempfile.new([ @basename, 'jpg' ].compact.join("."))
dst.binmode

cmd = %Q[-itsoffset #{time_offset} -i "#{File.expand_path(file.path)}" -y -vcodec mjpeg -vframes 1 -an -f rawvideo ]
cmd << "-s #{geometry.to_s} " unless geometry.nil?
cmd << %Q["#{File.expand_path(dst.path)}"]

begin
success = Paperclip.run('ffmpeg', cmd)
rescue PaperclipCommandLineError
raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if whiny
end
dst
end
end
end
```

This is the output from rails when I upload a file:

```
Started POST "/recordings" for 192.168.0.2 at 2011-11-20 21:27:39 +0000
Processing by RecordingsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xVX9V3e6bfXhfDLfjSKxtP9S3mxOFZzCyqeruJ2e/3c=", "recording"=>{"start_date(1i)"=>"2011", "start_date(2i)"=>"11", "start_date(3i)"=>"20", "start_date(4i)"=>"21", "start_date(5i)"=>"27", "end_date(1i)"=>"2011", "end_date(2i)"=>"11", "end_date(3i)"=>"20", "end_date(4i)"=>"21", "end_date(5i)"=>"27", "flagged"=>"0", "asset"=>#>, "motion"=>"", "motion_width"=>"", "motion_height"=>"", "motion_xcoord"=>"", "motion_ycoord"=>"", "motion_labels"=>"", "motion_noise"=>""}, "commit"=>"Create Recording"}
Command :: ffmpeg -itsoffset -4 -i "/tmp/stream20111120-6908-2m3d53.mp4" -y -vcodec mjpeg -vframes 1 -an -f rawvideo -s 36x36 "/tmp/stream20111120-6908-2m3d53.jpg20111120-6908-192gp5v"
Command :: ffmpeg -itsoffset -4 -i "/tmp/stream20111120-6908-2m3d53.mp4" -y -vcodec mjpeg -vframes 1 -an -f rawvideo -s 72x72 "/tmp/stream20111120-6908-2m3d53.jpg20111120-6908-13hlx8y"
Command :: ffmpeg -itsoffset -4 -i "/tmp/stream20111120-6908-2m3d53.mp4" -y -vcodec mjpeg -vframes 1 -an -f rawvideo -s 114x114 "/tmp/stream20111120-6908-2m3d53.jpg20111120-6908-yq9org"
MONGODB xanview2_development['system.namespaces'].find({})
[paperclip] Saving attachments.
[paperclip] saving /root/xanview2/public/uploads/4ec9/70d0/e0ed/181a/fc00/0002/original.mp4
[paperclip] saving /root/xanview2/public/uploads/4ec9/70d0/e0ed/181a/fc00/0002/small.jpg
[paperclip] saving /root/xanview2/public/uploads/4ec9/70d0/e0ed/181a/fc00/0002/medium.jpg
[paperclip] saving /root/xanview2/public/uploads/4ec9/70d0/e0ed/181a/fc00/0002/large.jpg
```

However when I try to access any of the "styles", I get this:

```
ruby-1.9.3-p0 :027 > Recording.all[0].asset
=> /assets/original/missing.png
ruby-1.9.3-p0 :028 > Recording.all[0].asset.styles
=> {:small=>#, :medium=>#, :large=>#}
```

Any ideas?