Class: DynamicFieldScaffoldGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/dynamic_field_scaffold_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_migrationObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/dynamic_field_scaffold_generator.rb', line 11

def generate_migration
  
  template "fields_table_migration.rb", "db/migrate/#{next_migration_number(Time.now)}_create_#{fields_table_name}.rb"
  template "fieldvalues_table_migration.rb", "db/migrate/#{next_migration_number(Time.now+1)}_create_#{fieldvalues_table_name}.rb"
  
  if use_fieldoptions_table
    template "fieldoptions_table_migration.rb", "db/migrate/#{next_migration_number(Time.now+2)}_create_#{fieldoptions_table_name}.rb"
  end
  
  if create_fieldgroup_table
    template "fieldgroups_table_migration.rb", "db/migrate/#{next_migration_number(Time.now+3)}_create_#{fieldgroup_table_name}.rb"
  end
  
  if create_models
    template "fields_model_template.rb", "app/models/#{fields_model_name.tableize.singularize}.rb"
    template "fieldvalues_model_template.rb", "app/models/#{fieldvalues_model_name.tableize.singularize}.rb"
    if use_fieldoptions_table
      template "fieldoptions_model_template.rb", "app/models/#{fieldoptions_model_name.tableize.singularize}.rb"
    end
    if use_fieldgroup_table
      template "fieldgroup_model_template.rb", "app/models/#{fieldgroup_model_name.tableize.singularize}.rb"
    end
  end

end