Sha256: 7659070acd0602bdc50bda08ba7cdf729016fb8f897d3dc41d058eac6bbf90ab
Contents?: true
Size: 1.04 KB
Versions: 89
Compression:
Stored size: 1.04 KB
Contents
module Avo module Fields class HasOneField < HasBaseField attr_accessor :relation_method 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 def label value.send(target_resource.title) end def resource Avo::App.get_resource_by_model_name @model.class end def frame_url Avo::Services::URIService.parse(@resource.record_path) .append_paths(id, value.id) .append_query(turbo_frame: turbo_frame) .to_s end def fill_field(model, key, value, params) if value.blank? related_model = nil else related_class = model.class.reflections[name.to_s.downcase].class_name related_model = related_class.safe_constantize.find value end model.public_send("#{key}=", related_model) model end end end end
Version data entries
89 entries across 89 versions & 1 rubygems