You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A hook to invoke the custom generator with scaffolding or with controller's generators
# lib/generators/rails/policy/hooks.rbrequire'rails/generators'require'rails/generators/rails/scaffold/scaffold_generator'require'rails/generators/rails/controller/controller_generator'Rails::Generators::ScaffoldGenerator.hook_for:policy,default: true,type: :boolean# invoke with scaffolding generatorsRails::Generators::ControllerGenerator.hook_for:policy,default: true,type: :boolean# invoke with the controllers' generator.
module ActiveModel
class Railtie < Rails::Railtie
generators do |app|
Rails::Generators.configure! app.config.generators
Rails::Generators::ControllerGenerator.include CustomPolicyGenerator::ControllerGenerator
Rails::Generators::ScaffoldControllerGenerator.include CustomPolicyGenerator::ScaffoldControllerGenerator
end
end
end
is the best way but outside of that, Rails::Generators::ScaffoldControllerGenerator is not defined and I am forced to use a require. If I use the requires:
Thanks yall. I wrote a blogpost to cover what ended up working for me. I did end up needing the requires, but I wasn't using custom templates so not sure if it breaks that like you mentioned.
Thanks for the effort.