Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/uploadbox/engine.rb

Instance Method Summary collapse

Instance Method Details

#uploads_many(upload_name, options = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/uploadbox/engine.rb', line 85

def uploads_many(upload_name, options={})
  upload_model_class = "Uploadbox::#{@object.class.base_class.to_s + upload_name.to_s.camelize}".constantize
  options.reverse_merge!(preview: upload_model_class.versions.keys.first,
                         namespace: false,
                         default: false,
                         update_label: 'Alterar',
                         choose_label: 'Escolher',
                         destroy_label: '×'.html_safe)
  dimensions = upload_model_class.versions[options[:preview]]
  @template.render partial: 'uploadbox/images/uploads_many', locals: {
    upload_name: upload_name,
    resource: @object,
    form: self,
    version: options[:preview],
    width: dimensions[0],
    height: dimensions[1],
    namespace: options[:namespace],
    default: options[:default],
    removable: upload_model_class.removable?,
    update_label: options[:update_label],
    choose_label: options[:choose_label],
    destroy_label: options[:destroy_label]
  }
end

#uploads_one(upload_name, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/uploadbox/engine.rb', line 40

def uploads_one(upload_name, options={})
  upload_model_class = "Uploadbox::#{@object.class.base_class.to_s + upload_name.to_s.camelize}".constantize

  if upload_model_class.versions.present?
    options.reverse_merge!(preview: upload_model_class.versions.keys.first,
                           namespace: false,
                           default: false,
                           update_label: 'Alterar',
                           choose_label: 'Escolher',
                           destroy_label: '×'.html_safe)
    dimensions = upload_model_class.versions[options[:preview]]
    @template.render partial: 'uploadbox/images/uploads_one', locals: {
      upload_name: upload_name,
      resource: @object,
      form: self,
      version: options[:preview],
      width: dimensions[0],
      height: dimensions[1],
      namespace: options[:namespace],
      default: options[:default],
      removable: upload_model_class.removable?,
      update_label: options[:update_label],
      choose_label: options[:choose_label],
      destroy_label: options[:destroy_label]
    }
  else
    options.reverse_merge!(namespace: false,
                           default: false,
                           update_label: 'Alterar',
                           choose_label: 'Escolher',
                           destroy_label: '×'.html_safe)
    dimensions = upload_model_class.versions[options[:preview]]
    @template.render partial: 'uploadbox/files/uploads_one', locals: {
      upload_name: upload_name,
      resource: @object,
      form: self,
      namespace: options[:namespace],
      removable: upload_model_class.removable?,
      update_label: options[:update_label],
      choose_label: options[:choose_label],
      destroy_label: options[:destroy_label]
    }
  end
end