Skip to content

Instantly share code, notes, and snippets.

@excid3
Created February 7, 2024 15:56
Show Gist options
  • Save excid3/47bdba1bdd1646e1da593998f647231c to your computer and use it in GitHub Desktop.
Save excid3/47bdba1bdd1646e1da593998f647231c to your computer and use it in GitHub Desktop.
Override rails:scaffold generator to add features like Turbo 8 refreshes
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