Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using HTML5 video tag in a simple rails app

Tags:

inside index.html.erb there is the following code

<video width="320" height="240" controls="controls">       <source src="truffle1.mp4"/>  Your browser does not support the video tag. </video> 

I am not sure where to put my mp4 video file so I put it at several places.
Next I fire up the rails server and use Chrome to open the index page. I see the black video frame but it does not play. and when I try open video in a new window. I get No route matches [GET] "/admin/truffle1.mp4" (note admin is just the namespace for the controller).


seems like this is a rails routing problem...

like image 432
delta2006 Avatar asked Nov 16 '11 03:11

delta2006


2 Answers

When you say src="truffle1.mp4"you're telling Rails to look for that file from the current route (you're probably on localhost:3000/admin if you're trying it on a local server, so it's looking in localhost:3000/admin/truffle1.mp4).

You could try giving it the route from the home of your app like so: src="/assets/media/truffle1.mp4", and put the file in that directory (you'll probably have to create it).

EDIT

Following the answer provided by @Pragnesh Vaghela, I managed to make it work. Your first intuition was right. You're missing routing if you want to have your videos in /assets/videos. When you say:

<%= video_tag "truffle1.mp4", :size => "320x240", :controls => true %> 

the server will look for the file in all the assets directories that have been routed (by default: stylesheets, images, and javascripts). If you put your video in images, it should work, for example. If you want to have the /assets/videos directory searched also, you have to add the following line to your config/application.rb file:

config.assets.paths << "#{Rails.root}/app/assets/videos" 

You can put it under the line that says:

config.assets.enabled = true 

I believe.

Hope this works.

like image 88
Pedro Cori Avatar answered Oct 31 '22 20:10

Pedro Cori


You can use the video_tag helper which builds an HTML 5 tag. Video files are loaded from 'public/videos' by default.

<%= video_tag "truffle1.mp4", :size => "320x240", :controls => true %> 
like image 35
Pragnesh Vaghela Avatar answered Oct 31 '22 19:10

Pragnesh Vaghela