Class: Avo::Fields::HasOneField
- Inherits:
-
HasBaseField
- Object
- BaseField
- HasBaseField
- Avo::Fields::HasOneField
- Defined in:
- lib/avo/fields/has_one_field.rb
Defined Under Namespace
Classes: IndexComponent, ShowComponent
Instance Attribute Summary collapse
-
#relation_method ⇒ Object
Returns the value of attribute relation_method.
Attributes inherited from HasBaseField
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #model, #null_values, #nullable, #panel_name, #readonly, #required, #sortable, #updatable, #user, #view, #visible
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #fill_field(model, key, value, params) ⇒ Object
- #frame_url ⇒ Object
-
#initialize(id, **args, &block) ⇒ HasOneField
constructor
A new instance of HasOneField.
- #label ⇒ Object
- #resource ⇒ Object
Methods inherited from HasBaseField
#target_resource, #turbo_frame
Methods inherited from BaseField
#component_for_view, #custom?, #database_id, #has_own_panel?, #hydrate, #model_errors, #name, #placeholder, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?
Methods included from FieldExtensions::HasFieldName
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(id, **args, &block) ⇒ HasOneField
Returns a new instance of HasOneField.
6 7 8 9 10 11 12 13 14 |
# File 'lib/avo/fields/has_one_field.rb', line 6 def initialize(id, **args, &block) super(id, **args, &block) hide_on :new, :edit @placeholder ||= I18n.t "avo.choose_an_option" @relation_method = name.to_s.parameterize.underscore end |
Instance Attribute Details
#relation_method ⇒ Object
Returns the value of attribute relation_method.
4 5 6 |
# File 'lib/avo/fields/has_one_field.rb', line 4 def relation_method @relation_method end |
Instance Method Details
#fill_field(model, key, value, params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/avo/fields/has_one_field.rb', line 28 def fill_field(model, key, value, params) if value.blank? = nil else = model.class.reflections[name.to_s.downcase].class_name = .safe_constantize.find value end model.public_send("#{key}=", ) model end |
#frame_url ⇒ Object
24 25 26 |
# File 'lib/avo/fields/has_one_field.rb', line 24 def frame_url "#{@resource.record_path}/#{id}/#{value.id}?turbo_frame=#{turbo_frame}" end |
#label ⇒ Object
16 17 18 |
# File 'lib/avo/fields/has_one_field.rb', line 16 def label value.send(target_resource.title) end |
#resource ⇒ Object
20 21 22 |
# File 'lib/avo/fields/has_one_field.rb', line 20 def resource Avo::App.get_resource_by_model_name @model.class end |