Sha256: 7e5784773f178990d4188186daf4c6f21b1a13406d07e770898720e0ec7c5b43

Contents?: true

Size: 982 Bytes

Versions: 41

Compression:

Stored size: 982 Bytes

Contents

class Formtastic::Inputs::SingleFileInput
  include Formtastic::Inputs::Base

  def to_html
    object = builder.object
    model_instance = object.send(method)
    model_class = object.class.reflect_on_association(method).klass

    html = template.raw("")
    html << template.content_tag(:label, method.to_s.humanize, class: "label")
    html << builder.fields_for(method, model_class.new) do |f|
      f.file_field :asset, accept: model_class.extension_white_list
    end

    if model_instance
      html << template.content_tag(:div, class: "file-description") do
        filename = model_instance.asset.file.try(:filename)
        f_html = template.raw("")

        if model_class.to_s.include?("Image")
          f_html << template.content_tag(:img, "", src: model_instance.asset.lalala_thumb.url)
        end

        if filename
          f_html << template.content_tag(:span, filename)
        end

        f_html
      end
    end

    input_wrapping { html }
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.181 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.180 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.179 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.178 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.177 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.176 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.170 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.168 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.165 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.162 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.161 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.160 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.157 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.156 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.155 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.154 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.153 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.152 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.149 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.146 lib/formtastic/inputs/single_file_input.rb