[RUBY] Post a video on rails

This is my first post. Please note that it may be a little difficult to see.

This time, it is a memorandum of the video upload function in rails. Personally, uploading videos using FFmpeg was difficult to understand, so I would like to explain it in an easy-to-understand manner.

environment

Ruby 2.6.5 Rails 6.0.3.2

I will start immediately

Terminal


rails new RailsApp

Create a Rails App in the terminal.

Gemfile


gem 'carrierwave'
gem 'mini_magick'

Added to Gemfile

Terminal


rails bundle install

Bundle install in the terminal.

Terminal


rails g uploader video
rails g scaffold post video:string

Create uploader and scaffold in terminal

Terminal


rails db:migrate

Don't forget to migrate

app/models/post.rb


mount_uploader :video, VideoUploader

Added to post.rb

app/uploaders/video_uploader.rb


def extension_whitelist
   %w(jpg jpeg gif png MOV wmv mp4)
end 

Remove the comment from the 38th line and add it

ruby:views/posts/_form.html.erb


<div class="field">
    <%= form.label :video %>
    <%= form.file_field :video, :accept => 'video/*' %>
</div>

I think it is text.field, so rewrite it to file.field.

ruby:app/views/posts/show.html.erb


<p>
  <%= link_to @post.video_url.to_s do %>
   <%= video_tag(@post.video.to_s) %>
  <% end %>
</p>

I think it is <% = @ post.video%>, so rewrite it. If you do not write <% = link_to @ post.video_url.to_s do%>, the video will not play even if you click it.

Thank you very much

I struggled to upload the video, so I hope you can do it easily.

Recommended Posts

Post a video on rails
How to insert a video in Rails
Try deploying a Rails app on EC2-Part 1-
Tailwind on Rails
Introducing Rspec, a Ruby on Rails test framework
[Ruby on Rails] A memorandum of layout templates
(Ruby on Rails6) Creating data in a table
[Ruby on Rails] Post editing function (update, delete)
I made a portfolio with Ruby On Rails
Launch Rails on EC2
Deploy RAILS on EC2
Ruby on Rails basics
Yay! I'm on Rails!
Ruby On Rails Association
A story comparing front frameworks on existing Rails applications
Build a Ruby on Rails development environment on AWS Cloud9
[How to insert a video in haml with Rails]
[Ruby on Rails] Post image preview function in refile
A high bill from AWS during development on rails ...
[Rails] Launch a new project
Resolve ActiveRecord :: NoDatabaseError on rails6
[rails] How to post images
Launch a terminal on VScode
Ruby on rails learning record -2020.10.03
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Install Sidekiq pro on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
[Ruby on Rails] Add a column with a foreign key constraint
Ruby on Rails basic learning ①
[Rails] Creating a search box
[Ruby on Rails] about has_secure_password
Record video on ubuntu18.04 LTS
Ruby on rails learning record-2020.10.07 ②
A note about the seed function of Ruby on Rails
Yay! I'm on Rails! Repetition
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
[Rails] Make a breadcrumb trail
Explanation of Ruby on rails for beginners ③ ~ Creating a database ~
Ruby on rails learning record -2020.10.06
Apply CSS to a specific View in Ruby on Rails
Ruby on Rails validation summary
How to insert a video
How to deploy a Rails application on AWS (article summary)
Ruby on Rails Basic Memorandum
I want to add a browsing function with ruby on rails
Ruby on Rails for beginners! !! Post list / detailed display function summary
Build a development environment where Ruby on Rails breakpoints work on Windows
(Ruby on Rails6) Creating a database and displaying it in a view
[Ruby on Rails] Posting function that only logged-in users can post
[Rails] How to put a crown mark on the ranking function
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS
Steps to build a Ruby on Rails development environment with Vagrant
(Ruby on Rails6) Create a function to edit the posted content
Ruby on Rails Overview (Beginner Summary)
How to deploy jQuery on Rails