Ruby on Rails - image upload with dropzone in nested form
Asked Answered
S

1

4

I want to upload multiple images with dropzone.js on new post form.(Rails 4) I can upload images smoothly but I can not associate with new post because it doesn't have an id yet.

To do this, what should be the strategy?

Thanks.

Stannite answered 29/11, 2014 at 19:42 Comment(0)
N
2

i had the same problem, don't know, whether my solution is by the book, but i solved it so that when i create new parent, it gets saved to database immediately and then goes straight into edit mode, when it already has an ID.

I have two models Location (parent - has many) and Photo (child belongs to).

In my location view i put:

<%= link_to t('new_location'), locations_path(:user_id => current_user.id), :method => :post, class: 'btn btn-success' %>

In my locations_controller.rb, i have redirect to edit action on create. And that is it. When you create new location, it gets immediately saved and redirected to edit action, where i can upload images via jquery belonging to that location, because it allready has an ID.

BR, Luka

Nucleonics answered 4/5, 2015 at 7:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.