Class: Symphonia::ModelAttributes::ReferenceAttribute

Inherits:
Attribute
  • Object
show all
Defined in:
lib/symphonia/model_attributes/attribute.rb

Instance Attribute Summary

Attributes inherited from Attribute

#filter, #format_options, #name, #options, #sort_column

Instance Method Summary collapse

Methods inherited from Attribute

#default?, #filter?, #format, #initialize, #input_options, #required?, #sort=, #sort?, #value

Constructor Details

This class inherits a constructor from Symphonia::ModelAttributes::Attribute

Instance Method Details

#format_value(view, value, _entity) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/symphonia/model_attributes/attribute.rb', line 149

def format_value(view, value, _entity)
  if value.is_a?(ActiveRecord::Associations::CollectionProxy) || value.is_a?(Array)
    value.collect { |v| view.link_to v.to_s, v, format_options }.join("\n").html_safe
  else
    view.link_to value.to_s, value, format_options
  end
end

#input_fieldObject



157
158
159
# File 'lib/symphonia/model_attributes/attribute.rb', line 157

def input_field
  nil
end

#titleObject



140
141
142
143
144
145
146
147
# File 'lib/symphonia/model_attributes/attribute.rb', line 140

def title
  if (ref = @klass.reflect_on_association(name)).macro == :belongs_to
    @klass.human_attribute_name(ref.foreign_key, @options[:i18n] || {})
  else
    super
  end

end