simple_form-polymorphic_associations 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21eb301ad8e23b16a046addbe1317cd2186e56f3bfe84a55efc776aea4a80a53
4
- data.tar.gz: 7dcd29e3e8f196de9b864e7078aa4c5b54c4cb33a84caa8ce25cd85936924bba
3
+ metadata.gz: 0beb264dc98808fcc7bfa4a1ab6ec2bc5219663398877f1487731cf9059ee31b
4
+ data.tar.gz: 86032e0623b65c0a3dd998cc7b5c6b84fc062fba9337139820bf3b85e524f8a6
5
5
  SHA512:
6
- metadata.gz: 4ba11da6f2849eb955a1a4c6d4bcc44c32f277af6f0c839462e4f4d5e2436c8089a728c02cc41123b3eeaf3ebddf288a61fd2bd40763ea2bdebcc3aa6e803837
7
- data.tar.gz: ff11030145dd42a9708eac2ebe875873c1a50254d8adfd07c009cb0406c2ff30b0ceb28d931f297263ef7d24b30b779085986a2b1a18f9de7f5530096f42f843
6
+ metadata.gz: '01261180fcd1e963563626f04bf25e4018e2b0d42b0a5474f827c37bed3f3e96a0959be69951094aaefa17423f71852fe1e8dbb066722124cb5e7ad76841aae0'
7
+ data.tar.gz: e25ca8e8f9a4631fee36fb20fdc9816096ee7b3a67b9fd13e038694a1bd82a442d41980248bb88325011391b9901e87748a730d551d6a4f6d67bfc170b5b782f
@@ -46,13 +46,16 @@ class PolymorphicAssociationInput < SimpleForm::Inputs::Base
46
46
  def input(wrapper_options = nil)
47
47
  ActiveSupport::SafeBuffer.new.tap do |o|
48
48
  collection = options[:classes].keys.collect { |c| [c.model_name.human, c] }
49
- label_method = :to_s
50
- value_method = :to_s
49
+ instance_label_method = options.delete(:instance_label_method) || :to_s
51
50
  o << @builder.select("#{attribute_name}_type", collection, { include_blank: true }, { class: 'form-control select required polymorphic-association-class-select' })
52
51
  options[:classes].each do |klass, url|
53
52
  o << "<a class=\"polymorphic-association-autocomplete-link\" data-class=\"#{klass}\" href=\"#{url}\" ></a>".html_safe
54
53
  end
55
- o << @builder.select("#{attribute_name}_id", [], {}, { class: 'form-control select required polymorphic-association-resource-select' })
54
+ id_select_collection = []
55
+ if selected_record = object.send(attribute_name).presence
56
+ id_select_collection << [selected_record.send(instance_label_method), selected_record.id]
57
+ end
58
+ o << @builder.select("#{attribute_name}_id", id_select_collection, {}, { class: 'form-control select required polymorphic-association-resource-select' })
56
59
  end
57
60
  end
58
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleFormPolymorphicAssociations
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form-polymorphic_associations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.4.21
66
+ rubygems_version: 3.3.26
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Simple Form polymorphic associations.