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



144
145
146
147
148
149
150
# File 'lib/symphonia/model_attributes/attribute.rb', line 144

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



152
153
154
# File 'lib/symphonia/model_attributes/attribute.rb', line 152

def input_field
  nil
end

#titleObject



136
137
138
139
140
141
142
# File 'lib/symphonia/model_attributes/attribute.rb', line 136

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