我正在编写一个 Rails 生成器,它将文件/文件夹从我的 gem 的模板目录复制到应用程序的目录中。它在我运行时按预期工作,rails generate mygem:install
但是当我尝试使用它来反转它时,rails destroy mygem:install
它不会删除新创建的子文件夹。
模板文件夹
├── templates
│ ├── views
│ │ ├── about
│ │ │ ├── index.html.erb
│ │ ├── contact
│ │ │ ├── index.html.erb
app 文件夹(生成后)
├── app
│ ├── views
│ │ ├── about
│ │ │ ├── index.html.erb
│ │ ├── contact
│ │ │ ├── index.html.erb
app 文件夹(销毁后)
├── app
│ ├── views
│ │ ├── about
│ │ ├── contact
期望的结果
├── app
│ ├── views
我的 gem 的安装生成器
module Mygem
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
def copy_templates
templates = Dir.glob("#{source_paths[0]}/*")
directory(templates[0], "app/views/")
end
end
end
end