Class: Models::Templates::Relation
- Inherits:
-
Base
- Object
- Base
- Models::Templates::Relation
- Defined in:
- app/components/databasium/models/templates/relation.rb
Instance Method Summary collapse
-
#initialize(relation: nil, models: nil) ⇒ Relation
constructor
A new instance of Relation.
- #view_template ⇒ Object
Constructor Details
#initialize(relation: nil, models: nil) ⇒ Relation
Returns a new instance of Relation.
6 7 8 9 |
# File 'app/components/databasium/models/templates/relation.rb', line 6 def initialize(relation: nil, models: nil) @relation = relation @models = models end |
Instance Method Details
#view_template ⇒ Object
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 36 37 38 39 40 41 42 43 44 45 |
# File 'app/components/databasium/models/templates/relation.rb', line 11 def view_template selected_relation = @relation&.fetch(:name, nil) selected_model = @relation&.fetch(:type, nil)&.classify div(class: "flex gap-2") do select( name: "model[relations][][type]", class: "border-2 rounded-xl p-1 border-border w-full bg-background focus:outline-none" ) do [ [ "belongs_to", "Belongs To" ], [ "has_many", "Has Many" ], [ "has_one", "Has One" ], [ "has_and_belongs_to_many", "Has And Belongs To Many" ] ].each do |value, label| option(value: value, selected: selected_relation == value) { label } end end input( type: "search", name: "model[relations][][table_name]", placeholder: "Search or select model", class: "border-2 rounded-xl p-1 border-border w-full bg-background focus:outline-none", value: selected_model, list: "models_datalist" ) { } ( type: "button", class: "text-red-500", data: { action: "click->relation#removeRelation" } ) { heroicon "x-mark", variant: :solid, options: { class: "w-8 h-8" } } end render_models_datalist end |