改变生成的脚手架模型的当前结果
我的目标是对当前的脚手架生成器进行一些涡轮添加。为此,我需要模型中的plural_model_name。我正在寻找一种方法来更改由rails gscaffold命令生成的输出模型。
class <%= singular_model_name %> < ApplicationRecord
broadcasts to: <%= plural_model_name %>
end
任何人都可以给我一个正确的方向推动吗?如果可以给出一些关于我应该将猴子补丁版本放在 /lib/
中的哪个文件夹中的说明,我也会非常感激。
我已经浏览了几乎所有的生成器这里 但我似乎无法掌握模型的处理位置。
与模型相反,我已经成功地能够更改 查看模板, 视图生成器,以及<一href="https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt" rel="nofollow noreferrer">控制器模板和<一个href="https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb" rel="nofollow noreferrer">ScaffoldControllerGenerator 用于脚手架发电机。
I aim to make some turbo additions to the current scaffold generator. For that i need the plural_model_name in the model. I am looking for a way to alter the output model, generated by the rails g scaffold
command.
class <%= singular_model_name %> < ApplicationRecord
broadcasts to: <%= plural_model_name %>
end
Can anyone give me a nudge in the right direction?, I would also be very thankful if some instructions can be given as to in which folder in /lib/
i am supposed to place the monkey-patched version.
I have been going through nearly all generators here but i cannot seem to get a grasp of where the model is taken care of.
Contrary to the model i have successfully been able to alter the view templates, view generator, and controller template and ScaffoldControllerGenerator for the scaffold generator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它在 https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/activerecord/lib/rails/generators/active_record/model/templates/model.rb.tt
你应该可以在那里添加它
其次,在 https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/activerecord/lib/rails/generators/active_record/model/model_generator.rb
It's defined in https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/activerecord/lib/rails/generators/active_record/model/templates/model.rb.tt
You should be able to add it there
Second, configure your options in https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/activerecord/lib/rails/generators/active_record/model/model_generator.rb