lib/compony/model_fields/association.rb in compony-0.0.7 vs lib/compony/model_fields/association.rb in compony-0.0.8
- old
+ new
@@ -4,14 +4,19 @@
def initialize(...)
super
resolve_association!
end
- def value_for(data, link_to_component: nil, link_opts: {}, controller: nil)
+ def value_for(data, link_to_component: nil, link_opts: {}, controller: nil, **_)
if link_to_component
fail('Must pass controller if link_to_component is given.') unless controller
return transform_and_join(data.send(@name), controller:) do |el|
- el.nil? ? nil : controller.helpers.compony_link(link_to_component, el, **link_opts)
+ next nil if el.nil?
+ if Compony.comp_class_for(link_to_component, el)
+ next controller.helpers.compony_link(link_to_component, el, **link_opts)
+ else
+ next el.label
+ end
end
else
return transform_and_join(data.send(@name), controller:) { |el| el&.label }
end
end