Created
February 7, 2024 15:56
-
-
Save excid3/47bdba1bdd1646e1da593998f647231c to your computer and use it in GitHub Desktop.
Override rails:scaffold generator to add features like Turbo 8 refreshes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScaffoldGenerator < Rails::Generators::NamedBase | |
source_root File.expand_path("templates", __dir__) | |
# Run rails:scaffold with the same arguments and options | |
hook_for :scaffold, in: :rails, default: true, type: :boolean | |
def turbo_refreshes | |
# Scaffold generator will have already removed this file on revoke | |
return if behavior == :revoke | |
inject_into_class File.join("app/models", class_path, "#{file_name}.rb"), class_name do | |
" broadcasts_refreshes\n" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment