For example have form with select box which has list of reasons and when user selects the reason we want to populate an amount field on the form. The reason table has the amount as one of its columns. In this example we have adjusments and adjustment_reasons when user creates a new adjustment they pick reason it populates the amount with default value from the adjustment reason.
We will create reason_controller.js in app/javascript/controllers
.
Model with accepted nested attributes stimulus controller to allow adding/deleting of rows to the nested input. e.g. TimeLog might have many TimeLogEntries
Change to accepts nested attributes
has_many :time_log_entries
accepts_nested_attributes_for :time_log_entries, allow_destroy: true
Putting modal dialog framework into Rails 7 application. Using this approach by David Colby. But not going as far as it does with dispatch events. As the article notes need to be on Turbo 7.2 at least.
We will create modal_controller.js in app/javascript/controllers
. Very similar to excid3 tailwind stimulus components modal component.
// This controller is an edited-to-the-essentials version of the modal component created by @excid3 as part of the essential tailwind-stimulus-components package found here:
View component I use for Index pages that are linked up to pagy and ransack, this component provides standard interface with title, subtitle, search, active filter and new button. Styling can change as required.
rails g component IndexContainer