Files
grecia/app/components/documents/nested_component.rb
Javi Martín b52ceb2c78 Move attachable methods from helpers to models
We were using helper methods inside the model; we might as well include
them in the model and use them from anywhere else.

Note we're using a different logic for images and documents methods.
That's because for images the logic was defined in the helper methods,
but for documents the logic is defined in the Documentable concern. In
the past, different documentable classes allowed different content
types, while imageable classes have always allowed the same content
types.

I'm not sure which method is better; for now, I'm leaving it the way it
was (except for the fact that we're removing the helper methods).
2021-09-11 17:05:00 +02:00

28 lines
587 B
Ruby

class Documents::NestedComponent < ApplicationComponent
attr_reader :f
def initialize(f)
@f = f
end
private
def documentable
f.object
end
def max_documents_allowed
documentable.class.max_documents_allowed
end
def note
t "documents.form.note", max_documents_allowed: max_documents_allowed,
accepted_content_types: Document.humanized_accepted_content_types,
max_file_size: documentable.class.max_file_size
end
def max_documents_allowed?
documentable.documents.count >= max_documents_allowed
end
end