attachinary icon indicating copy to clipboard operation
attachinary copied to clipboard

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

Open cantonic opened this issue 11 years ago • 1 comments

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 avatar Aug 27 '14 16:08 cantonic

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

cantonic avatar Aug 27 '14 18:08 cantonic