Sha256: a08a5e5fd6cc959f74890f22a50bb69555afea32440141718f67acb37aafde99
Contents?: true
Size: 1.81 KB
Versions: 3
Compression:
Stored size: 1.81 KB
Contents
module Voluntary module ShowHelper def show_attributes(*attributes) result = '' attributes.each {|attribute| result += show_attribute attribute} raw result end def show_attribute(attribute, options = {}) title = options[:title] || attribute_translation(attribute) value = options[:value] || resource.send(attribute) value.blank? ? '' : content_tag(:dt, title) + content_tag(:dd, value) end def show_associations(*associations) result = '' associations.each {|association| result += show_association association} raw result end def show_association(association) if association.to_s == association.to_s.pluralize return show_attribute( association, title: t("#{association}.index.title"), value: raw(resource.send(association).map{|a| link_to a.name, a}.join(', ')) ) end title = if general_attribute?(:parent) t("attributes.#{association}") else if resource.send(association) t("activerecord.models.#{root_model_class_name(resource.send(association)).underscore}") else t("activerecord.models.#{association}") end end if resource.send(association) show_attribute( association, title: title, value: link_to(resource.send(association).try(:name), resource.send(association)) ) else '' end end def show_actions result = content_tag :dt, raw(' ') result += content_tag :dd, render( partial: 'shared/resource/actions', locals: { type: root_model_class_name(resource).tableize, resource: resource } ) raw result end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
voluntary-0.2.2 | app/helpers/voluntary/show_helper.rb |
voluntary-0.2.1 | app/helpers/voluntary/show_helper.rb |
voluntary-0.2.0 | app/helpers/voluntary/show_helper.rb |