Class: ScaffoldPlus::Generators::HabtmGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- ScaffoldPlus::Generators::HabtmGenerator
- Defined in:
- lib/generators/scaffold_plus/habtm/habtm_generator.rb
Instance Method Summary collapse
Instance Method Details
#add_migration ⇒ Object
21 22 23 24 |
# File 'lib/generators/scaffold_plus/habtm/habtm_generator.rb', line 21 def add_migration return unless .migration? migration_template "habtm_migration.rb", "db/migrate/#{habtm_migration_name}.rb" end |
#add_to_models ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/scaffold_plus/habtm/habtm_generator.rb', line 26 def add_to_models inject_into_class "app/models/#{name}.rb", class_name do text = before_array.include?(name) ? "\n" : "" text << " has_and_belongs_to_many :#{other.pluralize}\n" text << "\n" if after_array.include?(name) text end inject_into_class "app/models/#{other}.rb", other.camelize do text = before_array.include?(other) ? "\n" : "" text << " has_and_belongs_to_many :#{table_name}\n" text << "\n" if after_array.include?(other) text end end |
#add_to_permit ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/generators/scaffold_plus/habtm/habtm_generator.rb', line 41 def add_to_permit return unless .permit? text = "{ :#{other}_ids => [] }" file = "app/controllers/#{table_name}_controller.rb" gsub_file file, /(permit\(.*)\)/, "\\1, #{text})" # Special case: no previous permit gsub_file file, /^(\s*params)\[:#{name}\]$/, "\\1.require(:#{name}).permit(#{text})" end |