Carrierwave upload with nested forms?

后端 未结 1 1904
孤城傲影
孤城傲影 2020-12-06 02:49

Not sure what\'s going on here, but I think my nested form partials are causing a problem for CarrierWave.

When I update a field with an uploaded file, nothing happe

相关标签:
1条回答
  • 2020-12-06 03:33

    Some possible solutions:

    • It looks like you have, but just to make sure - have you got accepts_nested_attributes on the household model?
    • Also, have you tried it without the partial to localise the problem?
    • Have you got Rmagick or minimagick on the PictureUploader model?

    And also you'll want to note of the known issue with Carrierwave and nested forms as detailed on the Carrierwave Wiki.

    The workaround is to add the method below:

    class Image < ActiveRecord::Base
      mount_uploader :image, ImageUploader
    
      def image=(val)
        if !val.is_a?(String) && valid?
          image_will_change!
          super
        end
      end
    
    end
    class Person < ActiveRecord::Base
      has_many :images
      accepts_nested_attributes_for :images
    end
    
    0 讨论(0)
提交回复
热议问题