The Easiest Way to Add Drag and Drop to Your Rails App

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

A step-by-step guide to implementing drag-and-drop reordering in Rails 8 without Node.js or Webpack. The approach uses SortableJS loaded via Importmaps and a minimal Stimulus controller that sends a PATCH request to update item positions. The tutorial covers adding a position column to the database, optionally using the acts_as_list gem, wiring up the HTML view with data attributes, writing the Stimulus controller, and adding the Rails route and controller action. The entire feature requires roughly 10 lines of JavaScript and standard Rails routing.

4m read timeFrom norvilis.com
Post cover image
Table of contents
STEP 1: The Database SetupSTEP 2: Pin SortableJS (Importmap)STEP 3: The HTML ViewSTEP 4: The Stimulus ControllerSTEP 5: The Rails Controller & RouteSummary

Sort: