brug-be / railsgirls_guide

New Rails Girls guide
http://brug-be.github.io/railsgirls_guide/
3 stars 5 forks source link

Note about the Youtube Addy gem #10

Closed djouuuuh closed 8 years ago

djouuuuh commented 9 years ago

We noticed that the Youtube Addy usage guide (on Github) is not enough explicit to get the solution quickly.

I had to browse Stackoverflow to figure out that, to display the iframe video in my introductions.html, I had to wrote the keyword "raw" (and I still don't know why):

<%=raw YouTubeAddy.youtube_embed_url("https://youtu.be/3x-ICT-0hLY",420,315) %>

Maybe other teams met the same problem...!

ddefrenne commented 9 years ago

I think the reason why the 'raw' wasn't mentioned on the gem's Github page, is because it focusses on using it in Ruby in general instead of just Rails.

The reason why you need to add the 'raw'-keyword, is because Rails will escape HTML by default, to prevent security risks. This means that the return value of YouTubeAddy#youtube_embed_url, which is a String, will just be added to the page as a string, instead of as an actual HTML-tag. Adding 'raw' will prevent this behavior and add the actual HTML-tag.

djouuuuh commented 9 years ago

Well, thank you very much for this clarification ;-)

mariusandra commented 9 years ago

I think we should also teach people how to find answers to their questions. This was one of the original "design goals" with the youtube_addy section --> for trainees to google the gem and look up its usage from its github page, as this is an action rails developers often perform.

Unfortunately I didn't test it through and the raw bit really needs to be explained in the guide. The alternative is to use some other gem or task, but a quick google gave no good results.