Remove duplication in max documents allowed code

This commit is contained in:
Javi Martín
2021-07-11 22:02:07 +02:00
parent a181052f0d
commit 67c29a7c5f
2 changed files with 2 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
<%= f.label :documents, t("documents.form.title") %> <%= f.label :documents, t("documents.form.title") %>
<p class="help-text"><%= documentables_note %></p> <p class="help-text"><%= documentables_note %></p>
<div id="nested-documents" data-max-documents-allowed="<%= documentable.class.max_documents_allowed %>"> <div id="nested-documents" data-max-documents-allowed="<%= max_documents_allowed %>">
<%= f.fields_for :documents do |documents_builder| %> <%= f.fields_for :documents do |documents_builder| %>
<%= render Documents::FieldsComponent.new(documents_builder) %> <%= render Documents::FieldsComponent.new(documents_builder) %>
<% end %> <% end %>

View File

@@ -23,6 +23,6 @@ class Documents::NestedComponent < ApplicationComponent
end end
def max_documents_allowed? def max_documents_allowed?
documentable.documents.count >= documentable.class.max_documents_allowed documentable.documents.count >= max_documents_allowed
end end
end end