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
#attach_scope, #description, #discreet_pagination, #display, #hide_search_input, #scope
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #index_text_align, #model, #null_values, #nullable, #panel_name, #readonly, #required, #sortable, #updatable, #user, #view, #visible
Attributes included from Concerns::HasHTMLAttributes
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
#authorized?, #component_for_view, #default_name, #field_label, #field_value, #has_own_panel?, #placeholder, #searchable, #target_resource, #turbo_frame, #use_resource, #visible_in_reflection?
Methods inherited from BaseField
#component_for_view, #custom?, #custom_name?, #database_id, #default_name, #has_own_panel?, #hidden_in_reflection?, #hydrate, #model_errors, #name, #placeholder, #plural_name, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?, #visible_in_reflection?
Methods included from FieldExtensions::HasFieldName
Methods included from Concerns::IsReadonly
Methods included from Concerns::IsRequired
Methods included from Concerns::HasHTMLAttributes
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on, #show_on_create, #show_on_update, #visible_on?
Methods included from Concerns::IsResourceItem
#is_field?, #is_main_panel?, #is_panel?, #is_tab?, #is_tab_group?, #is_tool?
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) hide_on :new, :edit super(id, **args, &block) @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
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/avo/fields/has_one_field.rb', line 31 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 27 28 29 |
# File 'lib/avo/fields/has_one_field.rb', line 24 def frame_url Avo::Services::URIService.parse(@resource.record_path) .append_paths(id, value.id) .append_query(turbo_frame: turbo_frame) .to_s end |
#label ⇒ Object
16 17 18 |
# File 'lib/avo/fields/has_one_field.rb', line 16 def label value.send(target_resource.title) end |