Render Video Using HTML5 in Rails App

Notes


In this lesson we will work on displaying a Lesson object's video if it exists. We will start in app/views/lessons/show.html.erb. We want create some HTML to display our video, but wrap it in a Ruby if statement so that the HTML is only created when a video is present for the Lesson object. Our show.html.erb file should have a code block like this after we make the changes:

<% if @lesson.video.attached? %>
   <video width="800" controls>
      <source src="<%= url_for(@lesson.video) %>" type="video/mp4">
      Your browser does not support HTML5 video.
   </video>
<% end %>

Now if we attach a video to a lesson and visit it's show view we can see the video displayed. The video player still needs some polish to be able to skip around in the video but our application is feature complete in the sense that we have the complete skeleton for what our application will be. From here on out it's all about polish and fleshing out the details.

Happy coding!!!!