Reputation:
I am trying to embed a youtube embed in a rails view
In the controller I have
@embed_code = '<iframe width="480" height="270" src="https://www.youtube.com/embed/#{video_id}?frameborder="0"allowfullscreen"></iframe>'
I am failing to find a way to write this to the view effective escaping and making html safe and display it as <%= @embed_code.html_safe %>
If anyone can offer some advice I would appreciate it I have walked myself in circles and am well confused at this stage. As far as I see it is the second quotes around the params causing the issue.
Upvotes: 0
Views: 1799
Reputation: 547
I think sanitize
maybe what you want
%= sanitize @article.body %>
def sanitize(html, options = {})
self.class.white_list_sanitizer.sanitize(html, options).try(:html_safe)
end
Upvotes: 0
Reputation: 4496
Controller:
@embed_code = %Q{<iframe.....#{video_id}..>...</iframe>}.html_safe
# or
@embed_code = ActiveSupport::SafeBuffer.new(%Q{<iframe.....#{video_id}..>...</iframe>})
View:
<%= @embed_code %>
Upvotes: 2