-
I would like to add 1 more view to get generated by If I could modify I started trying to monkey patch the file by doing something like this require 'tailwindcss-rails/generators/tailwindcss/scaffold/scaffold_generator'
Tailwindcss::Generators::ScaffoldGenerator.available_views = %w[index edit show new _form _list_view] but unlike the rails generators where I can do this for generating pundit policies require 'rails/generators'
require 'rails/generators/rails/scaffold/scaffold_generator'
# Invoke with scaffolding generators
Rails::Generators::ScaffoldGenerator.hook_for :policy, default: true, type: :boolean this one raises a I know this isn't a discussion forum, but any guidance would be greatly appreciated. I feel dumb for not figuring this out. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
@pas256 Thanks for asking this question. I'm not sure I'll be totally helpful, but I'll try. This gem's scaffold generator is a subclass of Are you saying that it's possible to add a view to the basic Rails scaffold, and that approach doesn't work with this gem? Or are you asking about adding views more generally? I'm not aware of any way to do what you're asking with vanilla Rails, but I'm also not deeply familiar with the stock generators. Edit: "I'm not aware" beyond what's suggested at https://guides.rubyonrails.org/generators.html which is to subclass the generator and set it as your app's default. Have you tried that? |
Beta Was this translation helpful? Give feedback.
-
Rails uses a unified "load path", and a gem will (usually) register its own resources such that Rails can find them by looking them up in the load path. That way you don't need to change so many things per gem you add (or remember to fix that when you remove them later). |
Beta Was this translation helpful? Give feedback.
-
This has been very helpful. Thank you. |
Beta Was this translation helpful? Give feedback.
Yeah it is possible. Well, sort of.
I was following this: https://gist.github.com/annikoff/331f785aa7a207a7945b1eca6eff526b to add pundit policy generation to my scaffolding. The technique it uses is to make a
hooks.rb
file that does the monkey patching.... however the approach of
require
ing inside of the generator config inconfig/application.rb
felt weird, and ended up causing theactive_record
generator to be skipped.¯\_(ツ)_/¯
This morning I have abandon that approach and went back to subclassing as you suggested. I have a working solution, and I am mostly happy with it, but it does have more duplicated code than is strictly necessary.
First, override the
scaffold_controller
generator: