Class: BaseEditingBootstrap::Generators::FieldOverrideGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
BaseEditingBootstrap::GeneratorsHelpers
Defined in:
lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb

Constant Summary collapse

TYPES =
%i[base date datetime decimal integer enum boolean]

Instance Method Summary collapse

Instance Method Details

#copy_form_partialsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/base_editing_bootstrap/field_override/field_override_generator.rb', line 21

def copy_form_partials
  if attributes.empty?
    say "Need one field"
  else

    base_path = class_to_view_path(name)

    readonly_suffix = options[:readonly] ? "_readonly" : ""

    attributes.each do |a|
      attr_name, type = a.split(":")

      type = :base if type.nil?
      type = type.to_sym
      raise "Type #{type} not found in #{TYPES}" unless TYPES.include?(type)
      copy_file "form_field/_#{type}#{readonly_suffix}.html.erb", File.join(*base_path,"form_field", "_#{attr_name}#{readonly_suffix}.html.erb")
    end
  end

end