0

Im not sure how to name this question, but Im stucked with kind of an reverse relations in Rails 4. Let me explain it on a real-life example


Order has_many OrderFiles and OrderFile belongs_to Order

My app logic is like this (marketplace like):

  1. User upload some file on the /create_new_order/ page. OrderFile object is saved to the database using form_for OrderFile.new
  2. User searching for the Performer of the Order, apply filters, etc..
  3. User click "Make order" and on certain person. Order object is created

But, how do I link OrderFile to the Order? It's quite simple when the Order is created first. But when the File is first, how may rails know which order_id link to?

Sergey Khmelevskoy
  • 2,429
  • 3
  • 19
  • 43
  • Similar to http://stackoverflow.com/questions/12350019/how-to-use-jquery-file-upload-to-upload-multiple-images-on-one-page-during-creat/12486426#12486426 , you may find a nudge in the right direction there. – Brad Werth Aug 01 '16 at 16:42
  • Do the steps need to separate? Looking at your logic, it seems like all those steps could happen on a single form and you can create both the Order and OrderFile together using [`nested attributes`](http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html) – Bart Jedrocha Aug 01 '16 at 17:23

0 Answers0