Reputation: 25
I need some help. My project is to build an app to workout. I don't want to host any video, so in my form I just save youtube links in my database instead of the actual videos. I don't know how to display the video when it comes from the link in my database, though. Any idea ?! thanks !
<div class="exercices">
<% for exercice in @workout.exercices %>
<div class="row">
<div class="col-md-4">
<video src="http://<%= exercice.link %>" ></video>
</div>
<div class="col-md-2"><%= exercice.number %></div>
<div class="col-md-6"><%= exercice.name %></div>
</div>
<% end %>
Upvotes: 0
Views: 1125
Reputation: 318
You can directly embed video like this to display your video from your link.
<iframe width="560" height="315" src="//www.youtube.com/embed/DokUjuZmpCE" frameborder="0" allowfullscreen></iframe>
to make things simpler add a helper method e.g
def embed(youtube_url)
youtube_id = youtube_url.split("=").last
content_tag(:iframe, nil, src: "//www.youtube.com/embed/#{youtube_id}")
end
Then in your view
<%= embed(exercice.link) %>
Add some CSS and you are good go.
Upvotes: 0
Reputation: 2784
You could use one of these to achieve that :
https://github.com/seanbehan/videojs_rails
https://github.com/tgezginis/video_player
Upvotes: 1