Class: Forms::Model

Inherits:
Components::Base
  • Object
show all
Includes:
Phlex::Rails::Helpers::ContentTag, Phlex::Rails::Helpers::FormWith, Phlex::Rails::Helpers::HiddenFieldTag, Phlex::Rails::Helpers::LinkTo, Phlex::Rails::Helpers::TurboFrameTag
Defined in:
app/components/databasium/forms/model.rb

Constant Summary collapse

TYPES =
%w[
  string
  text
  integer
  float
  double
  decimal
  boolean
  date
  datetime
  timestamp
  time
  binary
].freeze
SKIPPED_COLUMNS =
%w[created_at updated_at id].freeze

Instance Method Summary collapse

Constructor Details

#initialize(columns_names_types:, model:) ⇒ Model

Returns a new instance of Model.



28
29
30
31
# File 'app/components/databasium/forms/model.rb', line 28

def initialize(columns_names_types:, model:)
  @columns_names_types = columns_names_types
  @model = model
end

Instance Method Details

#view_templateObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/components/databasium/forms/model.rb', line 33

def view_template
  if @model
    form_with(
      method: :post,
      scope: :record,
      url: databasium.records_path,
      class:
        "border-b-1 border-border p-4 rounded-xl hidden max-h-100 overflow-y-auto flex-1",
      id: "addRecord",
      data: {
        table_target: "addRecordForm"
      }
    ) do |form|
      hidden_field_tag(:table, @model.name)
      div(class: "grid grid-cols-2 gap-4 w-fit") do
        render_fields(form)
        render_submit_button(form)
      end
    end
  end
end