Embossed paper clip, dry configuration

To upload my code for attachment images, I created an initializer to override the variable @default_optionsused by Paperclip.

This way, I do not need to specify again and again the URL, path and storage that I want.

I would like to take another step and include a check in it, but I cannot get it to work ...

Any idea?

EDIT 1: I want to at least check availability and size.

EDIT 2: part of my current code

module Paperclip
 class Attachment
   def self.default_options
     if Rails.env != "production"
       @default_options = {
         :url => "/assets/:class/:attachment/:id/:style/:normalized_name",
         :path => ":rails_root/public/assets/:class/:attachment/:id/:style/:normalized_name",
         :default_style => :original,
         :storage       => :filesystem,
         :whiny         => Paperclip.options[:whiny] || Paperclip.options[:whiny_thumbnails]
         }
      else
       ...
      end
   end
 end

normalized_name- external function, feat: http://blog.wyeworks.com/2009/7/13/paperclip-file-rename

EDIT 3:

This blog: http://omgsean.com/2009/02/overriding-paperclip-defaults-for-your-entire-rails-app/ shows the hash default_optionswith a key validations.

, .

+3
1

default_options ( ( ). , , . .

+1

Source: https://habr.com/ru/post/1787518/


All Articles