Sha256: 1a909670061dc478f164013ee452a621f23b733afd6f561ead99fc659307f484

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Carload
  module DashboardHelper
    def generate_input form, model_name, attribute_name, column
      if column.type == :integer and attribute_name =~ /_id/
        associated_model = attribute_name.sub('_id', '')
        label_attribute = Dashboard.model(model_name).associated_models[associated_model.to_sym]
        form.association associated_model,
          label_method: label_attribute,
          label: t("activerecord.models.#{associated_model}"),
          input_html: {
            class: 'use-select2',
            data: {
              placeholder: t('carload.placeholder.select', thing: t("activerecord.attributes.#{associated_model}.#{label_attribute}"))
            }
          }
      elsif needs_upload?(model_name, attribute_name) and image?(attribute_name)
        upload_image form: form, image_name: attribute_name, width: 150, height: 150
      else
        form.input attribute_name
      end
    end

    def generate_show object, attribute
      case attribute
      when Symbol
        object.send attribute
      when String
        eval "object.#{attribute.gsub('.', '&.')}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
carload-0.2.2 app/helpers/carload/dashboard_helper.rb
carload-0.2.1 app/helpers/carload/dashboard_helper.rb