Module: AttachmentHelper
- Defined in:
- app/helpers/attachment_helper.rb
Instance Method Summary collapse
- #attachment_field(object_name, method, options = {}) ⇒ Object
- #attachment_image_tag(record, name, *args, fallback: nil, format: nil, **options) ⇒ Object
- #attachment_url(record, name, *args, filename: nil, format: nil) ⇒ Object
Instance Method Details
#attachment_field(object_name, method, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/attachment_helper.rb', line 25 def (object_name, method, = {}) if [:object] cache = [:object].send(:"#{method}_attachment").cache if [:direct] host = Defile.host || root_url backend_name = Defile.backends.key(cache) [:data] ||= {} [:data][:direct] = true [:data][:as] = "file" [:data][:url] = File.join(host, defile_app_path, backend_name) end if [:presigned] and cache.respond_to?(:presign) signature = cache.presign [:data] ||= {} [:data][:direct] = true [:data][:id] = signature.id [:data][:url] = signature.url [:data][:fields] = signature.fields [:data][:as] = signature.as end end hidden_field(object_name, :"#{method}_cache_id", .slice(:object)) + file_field(object_name, method, ) end |
#attachment_image_tag(record, name, *args, fallback: nil, format: nil, **options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/attachment_helper.rb', line 13 def (record, name, *args, fallback: nil, format: nil, **) file = record.send(name) classes = ["attachment", record.class.model_name.singular, name, *[:class]] if file image_tag((record, name, *args, format: format), .merge(class: classes)) elsif fallback classes << "fallback" image_tag(fallback, .merge(class: classes)) end end |
#attachment_url(record, name, *args, filename: nil, format: nil) ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'app/helpers/attachment_helper.rb', line 2 def (record, name, *args, filename: nil, format: nil) file = record.send(name) filename ||= name.to_s backend_name = Defile.backends.key(file.backend) host = Defile.host || root_url File.join(host, defile_app_path, backend_name, *args.map(&:to_s), file.id, filename.parameterize("_")) end |