开发者

ROR: Paperclip styles

开发者 https://www.devze.com 2023-01-19 04:01 出处:网络
I have a model that handles all my upload开发者_运维知识库s 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-im

I have a model that handles all my upload开发者_运维知识库s 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)


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消