Drag and Drop File Uploads with Dropzone and StimulusReflex
StimulusReflex is mostly used to create reactive UIs using declarative markup (data-reflex=...), but a lot of power lies in invoking it from client-side code (i.e. stimulus controllers). In this article, we’ll explore how to orchestrate a rather complex interaction between front-end JavaScript code and server-side rendered HTML using the example of drag-and-drop file uploads to ActiveStorage. 1. Preface: App Structure As this blog post builds on parts of my StimulusReflex Patterns course, there is some app boilerplate I have to explain, but I promise it will be short. The example app I use in my course is a sound design mood board. Consider that our app knows a model called Board, which can hold a couple of Embeds: # app/models/board.rb class Board < ApplicationRecord has_many :embeds accepts_nested_attributes_for :embeds end
Minthesize Company Blog