Clyde T
Clyde T

Reputation: 141

Youtube embed - Ruby on rails

Sorry to ask this question that may seem easy for some but I'm pulling my hair since this morning for such a small thing.

I installed the gem Youtube_embeb (https://github.com/shir/youtube-embed/).

That allow to post a youtube link in iframe ... but it does not work!

I have a software form with a youtube_url field.

I do not understand because when I add:

require 'youtube_embed'

in my javascript.js, i have an error ...

couldn't find file 'youtube_embed' with type 'application/javascript'

Thx for you help.

Upvotes: 1

Views: 238

Answers (1)

xploshioOn
xploshioOn

Reputation: 4115

the problem seems simple, in the documentation it doesn't say that you need to add to application.js anything, if you see at the code of the gem, it doesn't have any js file.

so just add to your gemfile this line

gem 'youtube_embed'

run bundle install

and add this one to your application_helper for example so you can have that helper available on every view of the application. so add in application helper, this line

require 'youtube_embed'

Make sure to stop and start again the server, just to be sure that it loads the gem, and then you can just call on the view where you want to show the video, this line

<%= YoutubeEmbed::Video.iframe('https://www.youtube.com/watch?v=XD_e7T5WCqw') %>

and it just create some html with an iframe to show the video. you just have to add it where you want it to show and change the url for the video you want.

I tested the gem and it's working. just with those 3 lines.

having in mind that the gem is working, I can still suggest a simpler solution, remove the gems, add this helper

https://gist.github.com/a-barbieri/a93281cd5c01025664e5cbd781cd917c

following the instructions and then you can just call to

<%= get_video_iframe('https://www.youtube.com/watch?v=XD_e7T5WCqw') %>

Upvotes: 2

Related Questions