Это мой код в draft.rb. Он загружает одно изображение за раз. Я хочу внести изменения, чтобы добавить несколько изображений с помощью скрепки. Я новичок в rails. Может кто-нибудь помочь мне, пожалуйста.
class Draft < ApplicationRecord
acts_as_paranoid
enum status: [:pending, :accepted, :rejected]
enum action_by: [:agency, :commercial, :brand]
belongs_to :proposal
belongs_to :campaign
belongs_to :content
belongs_to :user
belongs_to :platform
belongs_to :brand
has_one :draft_moderation
after_initialize :set_default_status, :if => :new_record?
after_commit :set_draft_moderation, on: [:create, :update]
def set_default_status
self.status ||= :pending
end
def set_draft_moderation
user_campaign_token = UserCampaignToken.where(campaign_id: self.campaign_id)
return if (self.status != 'pending' || !user_campaign_token.present?)
draft_moderation = DraftModeration.where(draft_id: id)
draft_moderation.destroy_all if draft_moderation.present?
DraftModeration.create(draft_id: id, last_moderated_at: Time.now, agency_status: 'pending')
end
# Draft type allowed for upload.
def draft_type_allowed
['image/', 'video/']
end
has_attached_file :media, styles: { medium: '300x300>', thumb: '100x100>' }, if: :image?
validates_attachment_content_type :media, content_type: %r{\Aimage\/.*\z}, if: :image?
has_attached_file :media, if: :video?
validates_attachment_content_type :media, content_type: %r{\Avideo\/.*\z}, if: :video?
validates_attachment_size :media, less_than: 200.megabytes, if: :video?
def rejection_sms
"Dear #{user.first_name},\nLooks like you made a mistake in your campaign submission. Please check your mail to see what needs to be fixed.\nLove,\nTeam Plixxo"
end
def accepted_sms
"Dear #{user.first_name},\nYour post just got approved! You are ready to take it live on your social media channel!.\nLove,\nTeam Plixxo"
end
def video?
media.instance.media.instance.media_content_type =~ %r{(video)}
end
def image?
media.instance.media.instance.media_content_type =~ %r{(image)}
end
end