mrrooijen / mongoid-paperclip

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

undefined method `bson_type' for ActionDispatch::Http::UploadedFile #52

Closed emirkin closed 10 years ago

emirkin commented 10 years ago

undefined method `bson_type' for #ActionDispatch::Http::UploadedFile:0x00000106021618

(someone else submitted the same problem at http://stackoverflow.com/questions/22143969/undefined-method-bson-type-for-actiondispatchhttpuploadedfile0x007f9450; also, there is another similar issue here at https://github.com/meskyanichi/mongoid-paperclip/issues/34)

Here's my model:

class MediaSnippet < Snippet
    include Mongoid::Paperclip

    has_mongoid_attached_file :attachment,
        path: ':attachment/:id/:style/:basename.:extension',
        storage: :s3,
        url: ':s3_alias_url',
        s3_host_alias: "#{AWS_S3[:bucket]}.s3.amazonaws.com",
        s3_permissions: :private,
        s3_credentials: "#{Rails.root}/config/s3.yml",
        bucket: AWS_S3[:bucket]
        styles: {
          original: ['1920x1680>', :jpg],
          small: ['100x100#',   :jpg],
          medium: ['250x250',    :jpg],
          large: ['500x500>',   :jpg]
        },

    validate proc { attachment.exists? }

end
class Snippet
    include Mongoid::Document
    include Mongoid::Attributes::Dynamic
    include Mongoid::Timestamps

    embedded_in :session
        ...
end
class Session
    include Mongoid::Document
    include Mongoid::Timestamps

    embeds_many :snippets, validate: false, cascade_callbacks: true
end

My specs:

GIT
  remote: git://github.com/meskyanichi/mongoid-paperclip.git
  revision: 18e9d2d50a337f347e01776201a5f36dda2934cb
  specs:
    mongoid-paperclip (0.0.9)
      paperclip (>= 2.3.6)

GIT
  remote: git://github.com/mongoid/mongoid.git
  revision: dba1c17b1dba667e50347ab616aaf6f2e1bee094
  specs:
    mongoid (4.0.0.beta1)
      activemodel (>= 4.0.0)
      moped (~> 2.0.beta6)
      origin (~> 2.1)
      tzinfo (>= 0.3.37)

GIT
  remote: git://github.com/mongoid/moped.git
  revision: e238b4a757d64d980e3137c5b57a37a1729733a9
  specs:
    moped (2.0.0.beta6)
      bson (~> 2.2)
      connection_pool (~> 1.2)
      optionable (~> 0.2.0)

paperclip (4.1.1)
rails (4.0.2)
emirkin commented 10 years ago

Could this be related to https://github.com/mongoid/moped/issues/200? (@durran)

emirkin commented 10 years ago

Found the problem. Not a bug.

In my case, the model with the paperclip attachment was subclassed from another model. So, when creating it I had to supply the right "type" class. I was supplying a wrong class. As a result, the ActionDispatch::Http::UploadedFile field was not intercepted by paperclip and instead was treated as an ordinary mongoid field. Naturally, it failed at the first attempt for serialization.

dileeppdkr commented 10 years ago

Hi I am getting the same problem while updating the image. What is the solution for that. my code is

 clinics  = Clinic.where(:id => doctor_clinic_params[:doc_clinic_id])
  clinics.update(:clinic_logo => doctor_clinic_params[:clinic_logo])

class Clinic include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paperclip

has_mongoid_attached_file :clinic_logo, :path => ":rails_root/public/system/:attachment/:id/:style/:filename", :url => "/system/:attachment/:id/:style/:filename", :content_type => [ "image/jpg", "image/png", "image/bmp" ], :styles => { :small => "50x50", :large => "304x304" }

end

this is my code. I am getting undefined method `bson_type' for #ActionDispatch::Http::UploadedFile:0x00000001db23f0 error. Please help me. Thanks in Advance.