Sha256: e7bd58c91ca8ca668f01890ab26916cc4b58e1e97c9bc93a52eda1fe95ca79a6

Contents?: true

Size: 1.29 KB

Versions: 13

Compression:

Stored size: 1.29 KB

Contents

module Voluntary
  module CollectionHelper
    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
        
        begin
          link_to value, eval("#{root_model_class_name(resource).tableize.singularize}_path(resource)")
        rescue
          link_to value, eval("#{root_model_class_name(resource).constantize.table_name.singularize}_path(resource)")
        end
      elsif column.match('_id')
        association = nil
        
        begin
          association = resource.send(column.gsub('_id', '')) 
        rescue 
          association = eval("resource.#{alternative_value}") if alternative_value.present?
        end
        
        if association
          begin
            link_to(association.name, association)
          rescue NoMethodError
            link_to(association.name, resource_path(association))
          end
        else
          value
        end
      else
        resource.send(column) 
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
voluntary-0.7.1 app/helpers/voluntary/collection_helper.rb
voluntary-0.7.0 app/helpers/voluntary/collection_helper.rb
voluntary-0.6.0 app/helpers/voluntary/collection_helper.rb
voluntary-0.5.2 app/helpers/voluntary/collection_helper.rb
voluntary-0.5.1 app/helpers/voluntary/collection_helper.rb
voluntary-0.5.0 app/helpers/voluntary/collection_helper.rb
voluntary-0.4.0 app/helpers/voluntary/collection_helper.rb
voluntary-0.3.0 app/helpers/voluntary/collection_helper.rb
voluntary-0.2.4 app/helpers/voluntary/collection_helper.rb
voluntary-0.2.3 app/helpers/voluntary/collection_helper.rb
voluntary-0.2.2 app/helpers/voluntary/collection_helper.rb
voluntary-0.2.1 app/helpers/voluntary/collection_helper.rb
voluntary-0.2.0 app/helpers/voluntary/collection_helper.rb