Module: UppyUploaderHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/uppy_uploader_helper.rb

Overview

View helper: uppy uploader.

Instance Method Summary collapse

Instance Method Details

#file_uploader(options = {}) ⇒ String

Helper method for general file uploads

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 5)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 5MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: all files)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

Returns:

  • (String)

    the rendered uploader partial



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/helpers/uppy_uploader_helper.rb', line 148

def file_uploader(options = {})
  default_options = {
    endpoint: upload_images_path,
    max_files: 5,
    max_file_size: 5 * 1024 * 1024, # 5MB
    allowed_file_types: ['*/*'],
    hidden_field_name: 'upload_ids',
    auto_proceed: false,
    height: 300,
    note: 'Images and PDFs only, up to 5MB each',
    submit_button_text: 'Upload Files',
    form_url: '#',
    form_method: :post,
    form_local: true,
    resource_name: 'upload'
  }

  uppy_uploader(default_options.merge(options))
end

#image_uploader(options = {}) ⇒ String

Helper method for ImageKit image uploads (multiple images)

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 50MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: images)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

Returns:

  • (String)

    the rendered uploader partial



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'app/helpers/uppy_uploader_helper.rb', line 239

def image_uploader(options = {})
  default_options = {
    # CRM images endpoint only
    endpoint: upload_images_path,
    max_files: 10,
    max_file_size: 50 * 1024 * 1024, # 50MB
    allowed_file_types: ['image/*'],
    hidden_field_name: 'files[files_list]',
    auto_proceed: false,
    height: 400,
    note: 'Image files only, up to 10MB each',
    submit_button_text: 'Upload Images',
    form_url: { action: :create_multi },
    form_method: :post,
    form_local: true,
    resource_name: 'files',
    manual_submit: false # Auto-submit after upload
  }

  uppy_uploader(default_options.merge(options))
end

#large_file_uploader_s3(options = {}) ⇒ String

Helper method for large file uploads with S3 mode in existing uploader

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 1)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 500MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: all files)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • mode (String)

    upload mode (default: 's3')

Returns:

  • (String)

    the rendered uploader partial



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'app/helpers/uppy_uploader_helper.rb', line 310

def large_file_uploader_s3(options = {})
  default_options = {
    endpoint: upload_uploads_path, # Still needed for XHR fallback
    presigned_url_endpoint: presigned_url_uploads_path,
    upload_complete_endpoint: upload_complete_uploads_path,
    max_files: 1,
    max_file_size: 500 * 1024 * 1024, # 500MB
    allowed_file_types: ['*/*'],
    hidden_field_name: 'upload_ids',
    auto_proceed: true,
    height: 400,
    note: 'Large files up to 500MB - uploading directly to cloud storage for better performance',
    submit_button_text: 'Upload File',
    form_url: '#',
    form_method: :post,
    form_local: true,
    resource_name: 'upload',
    mode: 's3' # Use S3 mode
  }

  uppy_uploader(default_options.merge(options))
end

#lead_sketch_uploader(options = {}) ⇒ String

Helper method for lead form sketch uploads

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 250MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: all files)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • category (String)

    upload category (default: 'sketch')

Returns:

  • (String)

    the rendered uploader partial



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'app/helpers/uppy_uploader_helper.rb', line 178

def lead_sketch_uploader(options = {})
  default_options = {
    # Lead form uploads use the WWW uploads endpoint
    endpoint: upload_www_uploads_path,
    max_files: 10,
    max_file_size: 250 * 1024 * 1024, # 250MB per file to allow large docs/CAD
    # Accept virtually any file except executables
    allowed_file_types: ['*/*'],
    hidden_field_name: 'lead[sketch_drawings]',
    auto_proceed: false,
    height: 200,
    note: 'Attach project filesimages, PDFs, docs, CAD files, or ZIPs',
    submit_button_text: 'Upload Sketches',
    form_url: '#',
    form_method: :post,
    form_local: true,
    resource_name: 'lead',
    category: 'sketch'
  }

  uppy_uploader(default_options.merge(options))
end

#public_warranty_card_uploader(options = {}) ⇒ String

Helper method for warranty-card uploads on the PUBLIC registration form.
Files land unattached (7-day expiry) via the WWW endpoint and their ids
collect in the hidden field; Warranty::PublicRegistration claims them on
submit.

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 10MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: images or PDFs)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • category (String)

    upload category (default: 'warranty_card')

Returns:

  • (String)

    the rendered uploader partial



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/helpers/uppy_uploader_helper.rb', line 117

def public_warranty_card_uploader(options = {})
  default_options = {
    endpoint: upload_www_uploads_path,
    max_files: 10,
    max_file_size: 10 * 1024 * 1024, # 10MB
    allowed_file_types: ['image/*', 'application/pdf'],
    hidden_field_name: 'warranty_uploads[upload_ids]',
    auto_proceed: true,
    height: 200,
    note: 'Warranty card, receipt, or install photos — images or PDFs, up to 10MB each',
    submit_button_text: 'Upload Files',
    form_url: '#',
    form_method: :post,
    form_local: true,
    resource_name: 'warranty_uploads',
    category: 'warranty_card',
    manual_submit: false
  }

  uppy_uploader(default_options.merge(options))
end

#rma_image_uploader(rma, options = {}) ⇒ String

Helper method specifically for RMA image uploads

Parameters:

  • rma (Rma)

    the RMA the uploads attach to

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 10MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: images)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • category (String)

    upload category (default: 'photo')

Returns:

  • (String)

    the rendered uploader partial



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/uppy_uploader_helper.rb', line 43

def rma_image_uploader(rma, options = {})
  default_options = {
    endpoint: upload_uploads_path,
    max_files: 10,
    max_file_size: 10 * 1024 * 1024, # 10MB
    allowed_file_types: ['image/*'],
    hidden_field_name: 'rma[upload_ids]',
    auto_proceed: false,
    height: 400,
    note: 'Image files only, up to 10MB each',
    submit_button_text: 'Upload & Attach Images',
    form_url: do_add_multiple_images_rma_path(rma),
    form_method: :post,
    form_local: true,
    resource_name: 'rma',
    resource_type: 'Rma',
    resource_id: rma.id,
    category: 'photo',
    manual_submit: true
  }

  uppy_uploader(default_options.merge(options))
end

#rma_image_uploader_s3(rma, options = {}) ⇒ String

Helper method for RMA image uploads with S3 mode in existing uploader

Parameters:

  • rma (Rma)

    the RMA the uploads attach to

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 10MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: images)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • category (String)

    upload category (default: 'photo')

  • mode (String)

    upload mode (default: 's3')

Returns:

  • (String)

    the rendered uploader partial



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'app/helpers/uppy_uploader_helper.rb', line 273

def rma_image_uploader_s3(rma, options = {})
  default_options = {
    endpoint: upload_uploads_path, # Still needed for XHR fallback
    presigned_url_endpoint: presigned_url_uploads_path,
    upload_complete_endpoint: upload_complete_uploads_path,
    max_files: 10,
    max_file_size: 10 * 1024 * 1024, # 10MB
    allowed_file_types: ['image/*'],
    hidden_field_name: 'rma[upload_ids]',
    auto_proceed: true, # Auto-upload files immediately when dropped
    height: 400,
    note: 'Drop images here - they will upload automatically to cloud storage',
    submit_button_text: 'Upload & Attach Images', # Not used since manual_submit: false
    form_url: do_add_multiple_images_rma_path(rma),
    form_method: :post,
    form_local: true,
    resource_name: 'rma',
    resource_type: 'Rma',
    resource_id: rma.id,
    category: 'photo',
    manual_submit: false, # Auto-submit after upload
    mode: 's3' # Use S3 mode
  }

  uppy_uploader(default_options.merge(options))
end

#uppy_uploader(options = {}) ⇒ String

Helper method to render the uppy uploader with sensible defaults

Parameters:

  • options (Hash) (defaults to: {})

    locals for the shared/uppy_uploader partial

Options Hash (options):

  • endpoint (String)

    URL files are uploaded to

  • presigned_url_endpoint (String)

    URL that issues S3 presigned URLs (S3 mode)

  • upload_complete_endpoint (String)

    URL notified when an upload completes (S3 mode)

  • max_files (Integer)

    maximum number of files per upload session

  • max_file_size (Integer)

    maximum allowed file size in bytes

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (e.g. ['image/*'])

  • hidden_field_name (String)

    name of the hidden input collecting uploaded ids

  • auto_proceed (Boolean)

    whether uploads start immediately when files are dropped

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • form_url (String, Hash)

    URL the wrapping form submits to

  • form_method (Symbol)

    HTTP method for the wrapping form

  • form_local (Boolean)

    whether the wrapping form submits locally (no remote)

  • resource_name (String)

    param namespace the upload ids are submitted under

  • resource_type (String)

    class name of the record the upload attaches to

  • resource_id (Integer)

    id of the record the upload attaches to

  • category (String)

    upload category stored on the Upload record

  • manual_submit (Boolean)

    whether the user must submit the form explicitly

  • mode (String)

    upload mode ('s3' for direct-to-S3, otherwise XHR)

Returns:

  • (String)

    the rendered uploader partial



28
29
30
# File 'app/helpers/uppy_uploader_helper.rb', line 28

def uppy_uploader(options = {})
  render 'shared/uppy_uploader', options
end

#video_uploader(options = {}) ⇒ String

Helper method for video uploads

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 1)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 100MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: videos)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

Returns:

  • (String)

    the rendered uploader partial



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'app/helpers/uppy_uploader_helper.rb', line 210

def video_uploader(options = {})
  default_options = {
    endpoint: cf_upload_videos_path,
    max_files: 1,
    max_file_size: 100 * 1024 * 1024, # 100MB
    allowed_file_types: ['video/*'],
    hidden_field_name: 'video[cloudflare_uid]',
    auto_proceed: true,
    height: 400,
    note: 'Video files only, up to 100MB',
    submit_button_text: 'Upload Video',
    form_url: '#',
    form_method: :post,
    form_local: true,
    resource_name: 'video'
  }

  uppy_uploader(default_options.merge(options))
end

#warranty_card_uploader(warranty, options = {}) ⇒ String

Helper method for warranty-card uploads on CRM warranty pages. Uploads
attach to the persisted Warranty immediately (resource params on the
endpoint), so no separate submit step is needed.

Parameters:

  • warranty (Warranty)

    the warranty the uploads attach to

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • max_file_size (Integer)

    maximum allowed file size in bytes (default: 10MB)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: images or PDFs)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • category (String)

    upload category (default: 'warranty_card')

Returns:

  • (String)

    the rendered uploader partial



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/uppy_uploader_helper.rb', line 80

def warranty_card_uploader(warranty, options = {})
  default_options = {
    endpoint: upload_uploads_path,
    max_files: 10,
    max_file_size: 10 * 1024 * 1024, # 10MB
    allowed_file_types: ['image/*', 'application/pdf'],
    hidden_field_name: 'warranty[upload_ids]',
    auto_proceed: true,
    height: 300,
    note: 'Warranty cards — images or PDFs, up to 10MB each',
    submit_button_text: 'Upload Warranty Cards',
    form_url: '#',
    form_method: :post,
    form_local: true,
    resource_name: 'warranty',
    resource_type: 'Warranty',
    resource_id: warranty.id,
    category: 'warranty_card',
    manual_submit: false
  }

  uppy_uploader(default_options.merge(options))
end