Since there were few articles posting videos on Active Storage I challenged here without using carrier wave! !!
Currently, presense is not applied to the validates: video part. .. video_type → Specify by type because it is created enough to shoot with a mobile phone video_size → About 20MB in 10 seconds, so specify for the time being
#app/models/post.rb
class Post < ApplicationRecord
#abridgement
  with_options presence: true do
    validates :title
    validates :price, format: { with: /\A[-]?[0-9]+(\.[0-9]+)?\z/}
    validates_inclusion_of :price, in: 500..5000
    validates :video
  end
  validate :video_type
  validate :video_size
  private
  def video_type
    if !video.blob.content_type.in?(%('video/quicktime video/quicktime'))
        errors.add(:video, 'Please upload the video in mov format taken with your mobile phone')
    end
  end
  def video_size
    if video.blob.byte_size > 20.megabytes
      errors.add(:video, "Please retake the video short(Within 20MB)")
    end
  end
end
#app/views/posts/index.html.erb
class PostsController < ApplicationController
#abridgement
<video src=<%= rails_blob_path(post.video) %> type="video/mov", controls></video>
Recommended Posts