mrrooijen / mongoid-paperclip

Mongoid::Paperclip enables you to use Paperclip with the Mongoid ODM for MongoDB.
MIT License
344 stars 119 forks source link

do not mess with the id partition #59

Closed fuelxc closed 8 years ago

fuelxc commented 9 years ago

In paperclip 4.2 they already accept strings for the id's

The current implementation will break the id partition in non mongoid records. This fixes that.

ASnow commented 9 years ago

Agree with fuelxc And you can do something like this:

Paperclip.interpolates :id_partition do |attachment, style|
  if attachment.instance.ancestors.include? Mongoid::Paperclip
    attachment.instance.id.to_s.scan(/.{4}/).join("/")
  else
    case id = attachment.instance.id
    when Integer
       ("%09d" % id).scan(/\d{3}/).join("/")
    when String
      id.scan(/.{3}/).first(3).join("/")
    else
      nil
    end
  end
end
yordis commented 8 years ago

will break the id partition in non mongoid records

@fuelxc Why should be a non mongoid record at that point? Unless you tell me you want to have mongoid + activerecord, no?!?

fuelxc commented 8 years ago

I have an app with a need for both.

yordis commented 8 years ago

@fuelxc is there any way to monkey patch like @ASnow did but reusing the code of the paperclip implementation without copy and paste?

fuelxc commented 8 years ago

@yordis you could alias the method i suppose.

tilsammans commented 8 years ago

This will be fixed when #64 is merged.