assembler / attachinary

Attachments handler for Rails that uses Cloudinary for storage.
MIT License
295 stars 129 forks source link

Can't use attachinary in combination with rails_admin and MongoID in Rails 4 (validation error) #95

Open cantonic opened 10 years ago

cantonic commented 10 years ago

I want to use Attachinary in combination with rails_admin in Rails 4. I am using MongoID. My problem is, that the upload is working fine, but when trying to save a record through rails_admin I get a validation error that the image is not present.

this is my model:

class Medium
  include Mongoid::Document
  include Mongoid::Timestamps
  extend Enumerize

  has_attachment :image, accept: [:jpg, :png, :gif]

  accepts_nested_attributes_for :image

  validates :title, :image, presence: true

  field :title

  rails_admin do
    edit do
      field :title
      field :image do
        partial 'direct_image_upload'
      end
    end
  end
end

I had to use accepts_nested_attributes_for because else I got this error message:

Embbeded association without accepts_nested_attributes_for can't be handled by RailsAdmin, because embedded model doesn't have top-level access. Please add `accepts_nested_attributes_for :image' line to `Medium' model.

This is my partial (HAML):

.controls
  = cloudinary_js_config
  = form.attachinary_file_field :image

Do I need to create an additional Image model? Can't figure out why this is not working. Thank you very much for your help in advance.

cantonic commented 10 years ago

In the logs I see 406 Not Acceptable as the error message