paperclip - Rails 4, Simple Form, accepts_nested_attributes_for, Dropzone image upload -
is there way has_many association (user --> uploads) work nested form? have strong params working fine. users can have 5 images uploaded. using accepts_nested_attributes_for in model , uploading working, there gotchas.
but example when try edit user, , build new images using:
(5 - @user.uploads.count).times { @user.uploads.build }
...it builds 5 upload entries within nested form, no matter what. form section looks this:
<%= f.simple_fields_for :uploads |i| %> <hr> <% user.uploads.each |upload| %> <% if upload.image? %> <%= image_tag(upload.image.url(:medium), class: 'img-rounded').html_safe %> <br> <%= i.input :_destroy, as: :boolean, label: false, inline_label: 'remove picture', wrapper_html: { class: 'text-center' } %> <% end %> <% end %> <%= i.file_field :image %> <h4>or</h4> <%= i.input :image_remote_url, label: 'enter image url' %> <% end %>
previously had images uploading via dropzone ajax form, nested resource , url distinct uploads controller. have make uploads on same form user profile edit. ideally use dropzone on profile edit page, seems worse.
if has tips on how handle multiple file uploads (new / create , edit / update actions), can have limit of 5 uploads, i'd love hear it. also, implementation of multiple nested uploads via embedded dropzone better if possible.
Comments
Post a Comment