Simplify method names in image/document fields

We were using long, unique names because these methods used to be helper
methods. Helper methods should have unique names because otherwise one
method would overwrite the other.

Now that we're using components, we can omit the `image_` and
`document_` prefixes.
This commit is contained in:
Javi Martín
2021-06-20 19:17:29 +02:00
parent 8116e75aee
commit 21fee9cff5
4 changed files with 18 additions and 18 deletions

View File

@@ -12,11 +12,11 @@ class Documents::FieldsComponent < ApplicationComponent
f.object
end
def document_attachment_file_name
def file_name
document.attachment_file_name
end
def render_destroy_document_link
def destroy_link
if !document.persisted? && document.cached_attachment.present?
link_to t("documents.form.delete_button"),
direct_upload_destroy_path(
@@ -33,19 +33,19 @@ class Documents::FieldsComponent < ApplicationComponent
end
end
def render_attachment
def file_field
klass = document.persisted? || document.cached_attachment.present? ? " hide" : ""
f.file_field :attachment,
label_options: { class: "button hollow #{klass}" },
accept: accepted_content_types_extensions,
class: "js-document-attachment",
data: {
url: document_direct_upload_path,
url: direct_upload_path,
nested_document: true
}
end
def document_direct_upload_path
def direct_upload_path
direct_uploads_path("direct_upload[resource_type]": document.documentable_type,
"direct_upload[resource_id]": document.documentable_id,
"direct_upload[resource_relation]": "documents")