Refactor the selected code to be more idiomatic and maintainable
Refactor the following Ruby/Rails code to be more idiomatic, maintainable, and performant. Follow RuboCop style guidelines, SOLID principles, and modern Ruby and Rails conventions. Explain the key improvements you've made. If appropriate, suggest how this might work with Hotwire/Turbo/Stimulus.\n\nCode to refactor:\n{{selection}}