Class: Symphonia::ModelAttributes::ReferenceAttribute
- 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
- #format_value(view, value, entity) ⇒ Object
-
#initialize(name, klass, options, formatter) ⇒ ReferenceAttribute
constructor
A new instance of ReferenceAttribute.
- #input_field ⇒ Object
- #title ⇒ Object
Methods inherited from Attribute
#default?, #filter?, #format, #input_options, #required?, #sort=, #sort?, #value
Constructor Details
#initialize(name, klass, options, formatter) ⇒ ReferenceAttribute
Returns a new instance of ReferenceAttribute.
128 129 130 |
# File 'lib/symphonia/model_attributes/attribute.rb', line 128 def initialize(name, klass, , formatter) super end |
Instance Method Details
#format_value(view, value, entity) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/symphonia/model_attributes/attribute.rb', line 141 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, }.join("\n").html_safe else view.link_to value.to_s, value, end end |
#input_field ⇒ Object
149 150 151 |
# File 'lib/symphonia/model_attributes/attribute.rb', line 149 def input_field nil end |
#title ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/symphonia/model_attributes/attribute.rb', line 132 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 |