覆盖 haml-rails 脚手架模板

Overwrite haml-rails scaffold templates

我想自定义由 haml-rails. According to the Rails guide 生成的控制器视图我应该将我的自定义模板(例如 index.html.haml)放入 lib/templates/[subfolders]

在这种情况下,我尝试了几个子文件夹(例如 lib/templates/haml/scaffoldlib/generators/haml/scaffold/templates),但无法使用我的自定义模板。

我知道我可以轻松地编写另一个生成器,但我想知道是否有更 DRY 的方法来做到这一点。理论上应该可以:

In Rails 3.0 and above, generators don't just look in the source root for templates, they also search for templates in other paths.

我正在使用 Rails (4.2.5.2)haml (4.0.7)haml-rails (0.9.0)

天哪。毕竟它起作用了。将模板放入 lib/templates/haml/scaffold 是正确的。现在问题来了:spring 将缓存模板。因此,您必须在更改后重新启动 spring 或在生成器命令前添加 DISABLE_SPRING

DISABLE_SPRING=true rails g scaffold ...