Rails 3 + JQuery-File-Upload + Nested Model

前端 未结 3 643
面向向阳花
面向向阳花 2020-12-07 18:12

I\'ve been searching for some examples, but have come up short:

I\'m trying to implement JQuery-File-Upload on a project I\'m working on, but am getting lost as to h

3条回答
  •  一向
    一向 (楼主)
    2020-12-07 18:46

    I have coped with this problem and made a demo app to show how to do this.

    In short I have two models: item and upload.

    item.rb:

    has_many :uploads
    accepts_nested_attributes_for :uploads, :allow_destroy => true
    

    upload.rb:

    belongs_to :item
        has_attached_file :upload, :styles => { :large => "800x800", :medium => "400x400>", :small => "200x200>" }
    

    I added uploads_attributes to item controller.

    Now you can add jquery-file-upload form to your view, but there is one problem: it sends each photo in separate requests. So there is my jquery-file-upload initializer, which uploads all photos in one request (creating item model) and then redirecting to the root of your app (you need to use item form):

    
    

提交回复
热议问题