Uploading multiple files at once to Rails app with Carrierwave (HTML5)

后端 未结 2 345
情书的邮戳
情书的邮戳 2020-12-29 14:28

I\'m close...very close...I\'m able to upload single files just fine...but when i change the type of my form\'s file_field to :multiple => true

2条回答
  •  执念已碎
    2020-12-29 15:06

    Ditch accepts_nested_attributes_for and instead add this to your Gallery model.

    def photos=(attrs)
      attrs.each { |attr| self.photos.build(:image => attr) }
    end
    

    Also, make sure that photos is in your gallery's accessible attribs in case you're protecting against mass assignment. Otherwise you won't get the photos array hash assignment from your params. I.e.

    attr_accessible :field1, field2, :photos
    

提交回复
热议问题