Top Level Namespace

Defined Under Namespace

Modules: Mongoid, Paperclip

Instance Method Summary collapse

Instance Method Details

#id_partitionObject

the id of mongoid is not integer, correct the id_partitioin.



5
6
7
8
9
10
11
12
13
14
# File 'lib/mongoid_paperclip.rb', line 5

Paperclip.interpolates :id_partition do |attachment, style|
  case id = attachment.instance.id
  when Integer
    ("%09d".freeze % id).scan(/\d{3}/).join("/".freeze)
  when String
    id.scan(/.{4}/).join("/".freeze)
  else
    nil
  end
end