开发者

embedding a youtube video using haml/ruby on rails

开发者 https://www.devze.com 2023-03-22 00:53 出处:网络
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 ifra

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"}


I am not sure I got you correct, But you will be in need of player like flash player or something to render your video in the browser.

you may want to look these for reference.

rails 3 embed video

Easiest way to embed flash videos in Rails - must be cross browser compatible

If you are not looking for this, can you be more specific

0

精彩评论

暂无评论...
验证码 换一张
取 消