I thought I would contribute to the community by sharing how I solved this problem.
To summarize, the main problem was to reconcile the behavior of CarrierWave, nested forms and fine-grained control over file downloads.
The essence of the problem was that the nested forms create the root entry and all its associations in one POST operation for the #create action of the root controller.
In the above example, the recording model was the root, while AudioFile, Note, and Categorization were the associations created with the recording.
Thus, with nested forms, I would have to create all these entries in one POST, which would exclude the possibility of canceling the download separately or loading in parallel with the addition of other fields (for example, Notes).
This would not affect a good user interface. My solution was very simple:
- I decided not to use nested forms.
- The entry # create will always invoke with empty parameters. Record attributes will receive reasonable defaults in the create operation.
- The user will see the edit page of the entry No.
- On the entry edit page #, I had independent controls for CRUD operations on related models that would be routed to different controllers via AJAX calls. This worked because each associated model had a valid id_file to use.
- Various controllers will return HTML fragments that will be written to the main page of the recording.
This included inline editing of all the fields on the Record page, although these fields were mapped to different (related) models. Thus, the user will be able to upload multiple files, add notes while they are being downloaded, play already downloaded files, and cancel downloading as desired.
As a result, the entire user interface was much smoother. This would not be possible with nested forms by definition.
source share