diff --git a/app/models/form.rb b/app/models/form.rb index c70d3bd..a1a13ca 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -11,6 +11,15 @@ class Form < ApplicationRecord validates_presence_of :title + # TODO: use counter_cache option on association + def submissions_count + submissions.count + end + + def last_submission_date + submissions.order(created_at: :desc).first&.created_at + end + def deactivate!(reason = nil) self.user.deactivate!(reason) end diff --git a/app/views/forms/index.html.erb b/app/views/forms/index.html.erb index dc5f303..f3dcbe0 100644 --- a/app/views/forms/index.html.erb +++ b/app/views/forms/index.html.erb @@ -25,7 +25,7 @@
- <%= link_to form.google_spreadsheet_url, {:class => "has-text-success", :target => "__blank"} do %> + <%= link_to form.google_spreadsheet_url, {class: "has-text-success", target: "__blank"} do %> <% end %>
@@ -36,12 +36,12 @@
Submissions
-

42

+

<%= form.submissions_count %>

Last Submission
-

06.04.2020

+

<%= form.last_submission_date.to_formatted_s(:short) %>