From a709cd04794543e7bf160ee79ee9e1caf82fbabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 24 Jul 2017 16:19:35 +0200 Subject: [PATCH] Add accept HTML attribute to documents form file input. --- app/helpers/documentables_helper.rb | 6 ++++++ app/views/documents/_form.html.erb | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/helpers/documentables_helper.rb b/app/helpers/documentables_helper.rb index 77d1cbdf7..a9da06506 100644 --- a/app/helpers/documentables_helper.rb +++ b/app/helpers/documentables_helper.rb @@ -16,6 +16,12 @@ module DocumentablesHelper documentable.class.accepted_content_types end + def accepted_content_types_extensions(documentable) + documentable.class.accepted_content_types + .collect{ |content_type| ".#{content_type.split("/").last}" } + .join(",") + end + def humanized_accepted_content_types(documentable) documentable.class.accepted_content_types .collect{ |content_type| content_type.split("/").last } diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb index 6cb596a3a..11abe37f5 100644 --- a/app/views/documents/_form.html.erb +++ b/app/views/documents/_form.html.erb @@ -16,7 +16,9 @@
- <%= f.file_field :attachment, label: false, class: 'show-for-sr' %> + <%= f.file_field :attachment, + accept: accepted_content_types_extensions(@document.documentable), + label: false, class: 'show-for-sr' %> <%= f.label :attachment, t("documents.form.attachment_label"), class: 'button hollow' %>

<%= document_attachment_file_name(@document) %>