vendredi 6 janvier 2017

rails generate directory recursively

I am creating a gem which generates directory from template, in my template folder there is one folder which contains files and folder both. But when I tried to generate whole folder then it generates only files not internal folder.

Here you go:

In below image, that is my gem directory structure. I want to copy database_folder to rails app folder where gem will use. I have tried the simple code to copy directory.

see the directory structure in below image: enter image description here

require 'rails/generators'

module MyDb
  class InstallGenerator < Rails::Generators::Base
    desc 'Create individual forlder for each database and create corresponding migration generators.'
    source_root File.expand_path('../templates', __FILE__)

    def copy_folder_file
      ['database1', 'database2'].each do |db_name|
        directory 'database_folder', "#{db_name}"
      end
    end
  end
end

When I run my generator command:

rails g my_db:install

It generates the following:

enter image description here

Problem: is that, it skips migrate folder. But it should generate this folder.

Can you please do let me know, what I am missing.

Aucun commentaire:

Enregistrer un commentaire