Sha256: 455577cc62ac05a094d8f1165f55b7eac7281378c3334700238dfecea97c7096

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

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
      
      association ? link_to(association.name, association) : value
    else
      resource.send(column) 
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
voluntary-0.1.0 app/helpers/collection_helper.rb
voluntary-0.1.0.rc4 app/helpers/collection_helper.rb
voluntary-0.1.0.rc3 app/helpers/collection_helper.rb
voluntary-0.1.0.rc2 app/helpers/collection_helper.rb
voluntary-0.1.0.rc1 app/helpers/collection_helper.rb