From 17ce67db67f82a9306ab040d5395a66c42bf733e Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 17 Jul 2019 13:34:51 +0500 Subject: [PATCH] Add PersonComment#attachment --- app/models/person_comment.rb | 2 ++ app/policies/staff/person/person_comment_policy.rb | 2 +- .../staffs/people/person_comments/index.html.erb | 12 ++++++++++++ config/locales/activerecord/en.yml | 1 + config/locales/activerecord/ru.yml | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/person_comment.rb b/app/models/person_comment.rb index f9d42e0..a2cf8ea 100644 --- a/app/models/person_comment.rb +++ b/app/models/person_comment.rb @@ -11,6 +11,8 @@ class PersonComment < ApplicationRecord belongs_to :account, optional: true + has_one_attached :attachment + ############### # Validations # ############### diff --git a/app/policies/staff/person/person_comment_policy.rb b/app/policies/staff/person/person_comment_policy.rb index dc684a9..c2a4a79 100644 --- a/app/policies/staff/person/person_comment_policy.rb +++ b/app/policies/staff/person/person_comment_policy.rb @@ -10,7 +10,7 @@ class Staff::Person::PersonCommentPolicy < ApplicationPolicy end def permitted_attributes_for_create - %i[text] + %i[attachment text] end class Scope < Scope diff --git a/app/views/staffs/people/person_comments/index.html.erb b/app/views/staffs/people/person_comments/index.html.erb index 4799b8e..9a67fd5 100644 --- a/app/views/staffs/people/person_comments/index.html.erb +++ b/app/views/staffs/people/person_comments/index.html.erb @@ -11,6 +11,17 @@

<%= person_comment.text %> + + <% if person_comment.attachment.attached? %> +
+ + + + <%= link_to person_comment.attachment.blob.filename.to_s, + rails_blob_path(person_comment.attachment.blob, + disposition: 'download') %> + + <% end %>

@@ -33,6 +44,7 @@

<%= f.input :text %> + <%= f.input :attachment, direct_upload: true %>
diff --git a/config/locales/activerecord/en.yml b/config/locales/activerecord/en.yml index c29674a..eb3bc7c 100644 --- a/config/locales/activerecord/en.yml +++ b/config/locales/activerecord/en.yml @@ -81,6 +81,7 @@ en: place_of_birth: Place of birth person_comment: id: ID + attachment: Attachment text: Text person/sex: male: Male diff --git a/config/locales/activerecord/ru.yml b/config/locales/activerecord/ru.yml index 25f4e54..eddd53a 100644 --- a/config/locales/activerecord/ru.yml +++ b/config/locales/activerecord/ru.yml @@ -81,6 +81,7 @@ ru: place_of_birth: Место рождения person_comment: id: ID + attachment: Приложение text: Текст person/sex: male: Мужской