Sha256: d5163d5cf1c966d2956256f42b96ac8d3f83078dffc88baa6954fe3ab9131db4

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

module Voluntary
  module Helpers
    module Collection
      def table_cell column, resource, alternative_value = nil
        value = '-'
        
        if column == 'name'
          value = resource.send(column)
          
          if alternative_value.is_a?(Proc)
            return alternative_value.call(resource)
          elsif value.blank? && alternative_value.present? 
            value = eval("resource.#{alternative_value}")
          elsif value.blank?
            value = '-'
          end
          
          link_to value, eval("#{root_model_class_name(resource).tableize.singularize}_path(resource)")
        elsif column.match('_id')
          association = nil
          
          begin
            association = resource.send(column.gsub('_id', '')) 
          rescue 
            association = eval("resource.#{alternative_value}") if alternative_value.present?
          end
          
          association ? link_to(association.name, association) : value
        else
          resource.send(column) 
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
voluntary-0.1.0 lib/voluntary/helpers/collection.rb
voluntary-0.1.0.rc4 lib/voluntary/helpers/collection.rb
voluntary-0.1.0.rc3 lib/voluntary/helpers/collection.rb
voluntary-0.1.0.rc2 lib/voluntary/helpers/collection.rb
voluntary-0.1.0.rc1 lib/voluntary/helpers/collection.rb
voluntary-0.0.3 lib/voluntary/helpers/collection.rb
voluntary-0.0.2 lib/voluntary/helpers/collection.rb
voluntary-0.0.1 lib/voluntary/helpers/collection.rb