Class: Compony::ModelFields::Url

Inherits:
Base
  • Object
show all
Defined in:
lib/compony/model_fields/url.rb

Instance Attribute Summary

Attributes inherited from Base

#extra_attrs, #model_class, #name, #schema_key

Instance Method Summary collapse

Methods inherited from Base

#association?, #initialize, #label, #multi?, #schema_line, #simpleform_input, #simpleform_input_hidden, #transform_and_join

Constructor Details

This class inherits a constructor from Compony::ModelFields::Base

Instance Method Details

#value_for(data, controller: nil, **_) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/compony/model_fields/url.rb', line 4

def value_for(data, controller: nil, **_)
  return transform_and_join(data.send(@name), controller:) do |el|
    fail('Must pass controller to generate the link to the link.') unless controller
    return nil unless el
    return controller.helpers.link_to(el, el, target: '_blank', rel: 'noopener')
  end
end