简体   繁体   中英

ROR: Paperclip styles

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?

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)

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM