views:

411

answers:

4

I have a model that handles all my uploads of different filetypes.

  • How do I create a style with the same name as the :basename so that the url will be the same for images and non-image files?
A: 

Try this

class Upload < ActiveRecord::Base
  has_attached_file :photo, 
      :styles => {
        :thumb => {"115x70>"},
        :orig => {"300x168>"} }
        ..

As long as you specify two different styles, it'll create two different styles associated with your Upload object.

Then you can call them via :

= image_tag @upload.photo.url(:thumb)
= image_tag @upload.photo.url(:orig)
Trip
EDIT: Fat fingered that last comment. I have "has_attached_file :attached" which could be any kind of file with a method that checks if it's an image or not. Could I simply use after_create? I want every model that has and upload to call a thumbnail to be processed unless it's not a photo.
dah
This would be awesome if it wasn't for the fact that I have multiple file types on the same model.
dah
A: 

Huh?

http://rdoc.info/github/thoughtbot/paperclip/master/Paperclip/ClassMethods#has_attached_file-instance_method

The thumbnails will be created when the new file is assigned, but they will not be saved until save is called on the record. Likewise, if the attribute is set to nil is called on it, the attachment will not be deleted until save is called. See the Paperclip::Attachment documentation for more specifics.

Robert Lowe
I need it to save images to one particular path with a particular naming scheme :class_files/:id/:style.extension but use /:class_files/:id/:basename.:extension for non images. But they both need the same attribute on the model through has_attached_file.
dah
A: 

I know this is a simple question, but are you sure you have ImageMagick installed properly? Most problems that I've ran in to happen because ImageMagick isn't compiled/installed correctly. If you watch the logs, Paperclip will hum along and silently fail.

m3talsmith
Yup! I can make thumbs, but the issue is when it hits a file that isn't an image and tries to make thumbs.
dah
A: 

You are going to need to create a custom processor, then inside that processor you can call the IM methods for images and ignore the rest.

I didn't put much research into it, but this link might get you headed in the right direction: http://thewebfellas.com/blog/2009/2/22/video-thumbnails-with-ffmpeg-and-paperclip

Karl