Undefined Method 'metadata' when uploading using mongoid-paperclip gem-Record and share programming errors

As I said above, I had a similar problem with Mongoid, Carrierwave and GridFS. My solution is super hacky but it worked for me.

I had an Image class which is where my image was mounted

class Image
  include Mongoid::Document
  include Mongoid::Timestamps

  field :title
  field :image
  field :order

  mount_uploader :image, ImageUploader
  embedded_in :article

class Article
  include Mongoid::Document
  embeds_one :image

My carrierwave uploader wanted the attributes sent to it with the key of the mount uploader (image).

Image.create( :image => image_attributes)

But the article’s new/edit form created something that looked like:

:article => { :image => #ActionDispatch... }

instead of

:article => { :image => { :image => #ActionDispatch... } }

so my solution was to change the name of the field in the form to

file_field :article, :photo

and then add a photo setter to the article class that created an image

model Article
  include Mongoid::Document
  def photo=(attrs)
    create_image(:image => attrs)

I tried this with image= but it infinitely recursed and did evil things.
I also tried this

file_field "article[image]", :image

without the setter and it didn’t raise an exception but it also didn’t save my image.

as far as i know, paperclip is pretty similar in these regards. Maybe this will work for someone or someone can clean up my mess

Originally posted 2013-08-31 07:54:49.