Sha256: eaf90f20b0083e888a600be5dda05201318432cf372a70e5ded0d522201ad704
Contents?: true
Size: 1 KB
Versions: 43
Compression:
Stored size: 1 KB
Contents
module Avo module Fields class HasOneField < HasBaseField attr_accessor :relation_method def initialize(id, **args, &block) hide_on :forms super(id, **args, &block) @placeholder ||= I18n.t "avo.choose_an_option" @relation_method = name.to_s.parameterize.underscore end def label field_label end def frame_url Avo::Services::URIService.parse(field_resource.record_path) .append_paths(id, value.id) .append_query(query_params) .to_s end def fill_field(model, key, value, params) if value.blank? related_record = nil else related_class = model.class.reflections[name.to_s.downcase].class_name related_resource = Avo.resource_manager.get_resource_by_model_class(related_class) related_record = related_resource.find_record value end model.public_send("#{key}=", related_record) model end end end end
Version data entries
43 entries across 43 versions & 1 rubygems