lundi 11 décembre 2017

ROR - serving Random video_tag on on load / page refresh

Trying to serve a random video on each time a user either comes to the website or refreshes the homepage. This will allow it to look different and refreshing each time.

Current code for the home.html

<div class="home-banner basic-banner static video-container hidden-xs hidden-sm">

    <%= @random_video %><%= video_tag "test-3.mp4, test-4.mp4", autoplay: true, loop: true, muted: true, class: "video" %>
    <div class="container">
        <div class="title text-center">
            <h1 class="border border-color-white border-thick">PARADISE<br>BELOW</h1>
        </div>
    </div> 
</div>

Videos are coming from /app/assets/videos/

Static Controller

  def home
    @tour_category = TourCategory.all
       @videos  = ["app/assets/videos"]
       @random_no = rand(2)
       @random_video = @videos[@random_no]
  end

The random functions works, although it only displays the title of the video on on load or refresh. example: test-3.mp4

So now its only to get the videos to play correctly instead of showing the title.

Been looking at this for help: http://ift.tt/2knvqAM

Thanks for the help.




Aucun commentaire:

Enregistrer un commentaire