Sha256: 55cd26078724460e88b9a6120e104f0806cb83b28ed949da04a8417cb32eed01

Contents?: true

Size: 1.26 KB

Versions: 20

Compression:

Stored size: 1.26 KB

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 << label_html
    html << builder.fields_for(method, model_instance || model_class.new) do |f|
      f_html = template.raw("")
      f_html << f.file_field(:asset, accept: model_class.extension_white_list, id: input_html_options[:id])
      if model_instance
        f_html << template.content_tag(:div, class: "delete-button") do
          b_html = template.raw("")
          b_html << f.label(:_destroy, "delete")
          b_html << f.check_box(:_destroy)
          b_html
        end
      end
      f_html
    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

20 entries across 20 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.416 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.407 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.396 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.395 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.393 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.388 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.385 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.382 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.374 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.372 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.368 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.366 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.357 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.354 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.351 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.350 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.349 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.344 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.343 lib/formtastic/inputs/single_file_input.rb
lalala-4.0.0.dev.339 lib/formtastic/inputs/single_file_input.rb