Method: Alchemy::ResourcesHelper#render_attribute
- Defined in:
- app/helpers/alchemy/resources_helper.rb
#render_attribute(resource, attribute, options = {}) ⇒ String
Returns the value from resource attribute
If the attribute has a relation, the related object’s attribute value will be returned.
The output will be truncated after 50 chars. Pass another number to truncate then and pass false to disable this completely.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/alchemy/resources_helper.rb', line 74 def render_attribute(resource, attribute, = {}) attribute_value = resource.send(attribute[:name]) if attribute[:relation] record = resource.send(attribute[:relation][:name]) value = record.present? ? record.send(attribute[:relation][:attr_method]) : Alchemy.t(:not_found) elsif attribute_value && attribute[:type].to_s =~ /(date|time)/ localization_format = if attribute[:type] == :datetime [:datetime_format] || :"alchemy.default" elsif attribute[:type] == :date [:date_format] || :"alchemy.default" else [:time_format] || :"alchemy.time" end value = l(attribute_value, format: localization_format) elsif attribute[:type] == :boolean value = attribute_value ? '<alchemy-icon name="check"></alchemy-icon>'.html_safe : nil else value = attribute_value end .reverse_merge!(truncate: 50) if [:truncate] value.to_s.truncate(.fetch(:truncate, 50)) else value end end |