Embed a video on youtube using haml / ruby ​​on rails

advertisements

I have a website with a textarea that prompts users to input a URL from a youtube video. Once the user saves the page (thereby saving the embed code) I would like to implement an iframe on the page so that users can see the video they embedded.

at present the code that i have looks like this, where video_URL is the textarea where the user defines the URL:

= f.text_area :video_URL, :placeholder => "Please place the URL code from your YouTube or Vimeo here.", :rows => 1

%iframe{:height => 390, :width => 480, :frameborder => "0", :src => "view?step=micro_pitch/@project.micro_pitch"}

Any help would be greatly appreciated! Thank you so much!


2 ways, the new and the old:

Save the id of the video in @video_id

-1. the new with iframe:


        iframe{:allowscriptaccess => "always", :allowFullScreen => "true", :frameborder => "0", :height => "430", :src => "http://www.youtube.com/embed/#{@video_id}", :title => "YouTube video player", :width => "640"}

-2. The old with embed:


%object{:height => "0", :width => "0"}
        %param{:name => "movie", :value => "http://www.youtube.com/v/#{@video_id}?fs=1&hl=en_US&rel=0"}
        %param{:name => "allowFullScreen", :value => "true"}
        %param{:name => "allowscriptaccess", :value => "always"}
        %embed{:allowfullscreen => "true", :allowscriptaccess => "always", :height => "390", :src => "http://www.youtube.com/v/#{@video_id}?fs=1&hl=en_US&rel=0", :type => "application/x-shockwave-flash", :width => "640"}