Ruby on Rails #153 Refactoring Hotwire Modals

21/11/2023 (5 months ago)

I AM SORRY for not providing the complete, best approach right away.

In E151 we connected turbo frame modals with the html dialog element.

However this approach was not optimal:

  • We were needlessly adding a stimulus controller on the BODY html tag;
  • dialog html was present in the layout file, even if we do not need it right now;

Let's clean up the mess and make our modals even better! ✨

Special thanks to @ledockol for pushing me on this one! 💪

Episode source code:
Based on this blogpost:

0:00 old implementation
1:12 move modal dialog from body to new.html.erb
5:40 reusable dialog wrapper
7:59 restrict opening modals in new tabs

Sign in to join the conversation