All threads / Embed Youtube video in Rails app

Ask A Question


You’re not receiving notifications from this thread.

Embed Youtube video in Rails app

Markus asked in Rails


How is possible to embed an existing video an show it in a page with rails?

I followed this guide with yt gem:
So now I can post a youtube link and save it in the databse...
but doesn't explain how to embed the video and show it directly in the app...

Thank you very much!

The way I embed youtube videos on GoRails is that I have an Episode model with a column for youtube_id and when you click on an episode I embed it like the following (no need to use their API which is great):

<iframe src='<%= @episode.youtube_id %>?rel=0&autoplay=<%= params[:autoplay] || 0 %>' frameborder='0' allowfullscreen></iframe>

Thank you very much!!! Your answers are very helpful.

Could you add a go rails episode on this topic?

I think there's not much more to the topic than the answer above. Any specific issue you are running into?

I tried the above and it doesn't work. Where exactly do you place the youtube video id?

@Zanger02, right where it says <%= @episode.youtube_id %> in

<iframe src='<%= @episode.youtube_id %>?rel=0&autoplay=<%= params[:autoplay] || 0 %>' frameborder='0' allowfullscreen></iframe>

Which would render something like:

<iframe class="embed-responsive-item" src=";autoplay=1" frameborder="0" allowfullscreen=""></iframe>

This assumes you're passing an @episode object that has an attribute named youtube_id - your specific app may vary.

Did someone try using video_tag or video.js? I working on a product that needs to display different video sources and having to embed different iframes/players depending on the source is not quite an option.

Well, I never tried to embed a youtube video but would like to try it once at least. For now, I was reading an article about who is the most subscribed youtuber which I found really cool. They have provided the best ideas regarding most subscribed YouTubers here.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 49,439+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.