This time I will post for the first time. Please understand that it may be difficult to see.
This time, it is a memorandum of video upload function with rails. I personally found it difficult to understand how to upload videos using FFmpeg, so I hope I can explain as easily as possible.
Ruby 2.6.5 Rails 22.214.171.124
Get started immediately
rails new RailsApp
Create RailsApp in the terminal.
Add to Gemfile
rails bundle install
Do bundle install in the terminal.
rails g uploader video rails g scaffold post video:string
Create uploader and scaffold in terminal
Don’t forget to migrate
mount_uploader :video, VideoUploader
Added to post.rb
def extension_whitelist %w(jpg jpeg gif png MOV wmv mp4) end
Remove comment from line 38 and add
<div class="field"> <%= form.label :video %> <%= form.file_field :video, :accept =>'video/*' %> </div>
I think that it is text.field, so rewrite it as file.field.
<p> <%= link_to @post.video_url.to_s do %> <%= video_tag(@post.video.to_s) %> <% end %> </p>
I think it is <%= @post.video %> so I will rewrite it. If you do not write <%= link_to @post.video_url.to_s do %>, it will not play even if you click the video.
Thank you very much
I’ve had a hard time uploading videos, so I hope you guys made it easy.