Class: UploaderInput

Inherits:
Formtastic::Inputs::FileInput
  • Object
show all
Defined in:
app/inputs/uploader_input.rb

Instance Method Summary collapse

Instance Method Details

#base_idObject



47
48
49
# File 'app/inputs/uploader_input.rb', line 47

def base_id
  input_html_options[:id] || method
end

#cache_htmlObject



16
17
18
# File 'app/inputs/uploader_input.rb', line 16

def cache_html
  builder.hidden_field("#{method}_cache_id", :value => object.send("cached_#{method}").try(:id), :id => "#{base_id}_cache")
end

#existing_htmlObject



24
25
26
27
28
29
30
31
32
# File 'app/inputs/uploader_input.rb', line 24

def existing_html
  if method_present?
    existing = template.(:span, object.send("cached_#{method}").try(:original_filename))
    template.(:div, :id => "#{base_id}_existing", :class => 'cache_existing') do
      template.link_to(existing, Rails.application.routes.url_helpers.file_upload_cache_cached_file_path(object.send("cached_#{method}").try(:id))) <<
      template.(:span, " replace", :id => "#{base_id}_replace")
    end
  end or "".html_safe
end

#file_htmlObject



20
21
22
# File 'app/inputs/uploader_input.rb', line 20

def file_html
  builder.file_field(method, input_html_options.merge(:class => 'cached_file', :id => base_id))
end

#method_present?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/inputs/uploader_input.rb', line 6

def method_present?
  object.send(method).present?
end

#replace_htmlObject



34
35
36
# File 'app/inputs/uploader_input.rb', line 34

def replace_html
  file_html
end

#to_htmlObject



38
39
40
41
42
43
44
45
# File 'app/inputs/uploader_input.rb', line 38

def to_html
  input_wrapping do
    label_html <<
    cache_html <<
    existing_html <<
    file_html
  end
end

#wrapper_html_optionsObject



10
11
12
13
14
# File 'app/inputs/uploader_input.rb', line 10

def wrapper_html_options
  super.tap do |options|
    options[:class] << " present" if method_present?
  end
end