Ruby on Rails- HTML5 Video as background for landing page not loading on heroku

I'm trying to include a video as background in my application's landing page.

Placed the video in assets/videos folder.

Added `config.assets.paths << "#{Rails.root}/app/assets/videos"` to production.rb file.

  The code:

    <%= video_tag "Video.webm", controls: false, autoplay: true, muted: true, loop: true, id: "bgvideobg", class: "fullscreen-bg-video", type: "video/webm" %>

It works fine in my local machine.

I pre-compiled the assets locally using `bundle exec rake assets:precompile RAILS_ENV=production` and pushed onto heroku.

For some reason the video is not playing/streaming on server.

In logs it shows as

    ActionController::RoutingError (No route matches [GET] "/assets/Video-3a82304f95c15edbdd93924fe27e9b42.webm"):

I've checked my public/assets folder and file "Video-3a82304f95c15edbdd93924fe27e9b42.webm" does exist.

Any help would be highly appreciated. Thanks.

Can you post what you have in routes.rb? If the logs show RoutingError it's most likely a bug in there (although I have no idea why it would work on your local machine if that's the case).

Even I'm not sure why its working on my local machine and not on heroku. But I don't think it has something to do with my routes.rb file because it is not able to find an asset which was placed in my assets/videos folder and then precompiled.

After trying so many things I did the following

In my production.rb file I had config.assets.compile = false, and I changed its value to true. Now video is loading.

I don't know what will be the implications of changing its value from false to true, but it seems to work. Not only video the whole application.

I want to know if there will be any consequences for changing its value from false to true like load time or any other.

Thank You.

It will not work like this on Heroku

read this and make sure you did everything right

Hi. I think I have followed everything mentioned in the above mentioned post "https://devcenter.heroku.com/articles/rails-asset-pipeline&quot;\.

Reading further I saw about "sprockets_better_errors" in the article and included it in my gemfile.

Now when I run in my local machine I'm getting the following error.

ActionView::Template::Error (wrong number of arguments (2 for 1)):     3: <div class="bgvideo1">     4: <div class="videowrap">     5:     6: <%= video_tag "video.webm", controls: false, autoplay: true, muted: true, loop: true, id: "bgvideobg", class: "fullscreen-bg__video", type: "video/webm" %>     7:     8:     9: </div>

That is a bit odd as video_tag should accept two args. That sort of issue may mean that the error is not actually where it seems to be. Try fiddling with the video_tag line to get some clues. Take it out, change it to just one arg, and so on find out what the real problem is.

Colin

Tried many combinations with video_tag. Still it shows the same error.

Please quote the previous message when replying, otherwise it is difficult to follow the thread, this is a mailing list not a forum (though you may be using it via a forum like interface). Thanks.

Does the error disappear if you remove that line entirely? What if you move it to a completely different part of the view? What happens if you call video_tag with no parameters at all? What if you put a different helper such as field_tag in that line instead.

Does the error only appear if you include the gem sprockets_better_errors?

Which versions of ruby and rails are you using?

Colin

Tried many combinations with video_tag. Still it shows the same error.

Even when you switch it to one arg? I don't see how that's possible considering the error seems to think that's the number of arguments you should have.

Colin Law wrote in post #1181474:

Tried many combinations with video_tag. Still it shows the same error.

Please quote the previous message when replying, otherwise it is difficult to follow the thread, this is a mailing list not a forum (though you may be using it via a forum like interface). Thanks.

Does the error disappear if you remove that line entirely? What if you move it to a completely different part of the view? What happens if you call video_tag with no parameters at all? What if you put a different helper such as field_tag in that line instead.

Does the error only appear if you include the gem sprockets_better_errors?

Which versions of ruby and rails are you using?

Colin

Sorry Colin. I did not know I have to use previous message when replying. I was using it as a forum. Will do it from now.

Coming to my version I'm Ruby 2.2.2p95 and Rails 4.2.0.

That error is behaving very different. It showed the same error when I replaced it with image_tag. When I removed it completely it moved to my next image_tag. When I removed all my image_tags from my landing page it showed the same error at    "<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>"

It is showing the error only when I include the sprockets_better_errors gem. Now I've removed it and everything works fine.

But my my initial problem still exists. Video not loading on heroku. its working only if I change "config.assets.compile" value to true in my production.rb file.

So now I'm unsure if it will have any other affect on my application like slowing it down...etc.

Thanks.

Justin Yoon wrote in post #1181491:

Tried many combinations with video_tag. Still it shows the same error.

Even when you switch it to one arg? I don't see how that's possible considering the error seems to think that's the number of arguments you should have.

Hi Justin,

Even I don't understand it. It is showing this kind of behavior only if I include "sprockets_better_errors" gem. Else its working fine.

This suggests that gem has not been updated for two years and is not compatible with rails 4.2 https://rubygems.org/gems/sprockets_better_errors/versions/0.0.5

Colin

Colin Law wrote in post #1181533:

I am not an expert in that area, nor in Heroku. Have you determined whether it is a Heroku issue or a production environment issue? If not then try running it locally but in production mode and see what happens.

Colin

But changing "config.assets.compile" to true in production.rb file have any affect on my application?

Found this StackOverflow page that talks about this: config.assets.compile=true in Rails production, why not? - Stack Overflow. Not sure how helpful it is but hopefully you'll get some answers out of it.

Justin Yoon wrote in post #1181553:

But changing "config.assets.compile" to true in production.rb file have any affect on my application?

Found this StackOverflow page that talks about this:

config.assets.compile=true in Rails production, why not? - Stack Overflow.

Not sure how helpful it is but hopefully you'll get some answers out of it.

Hi Justin,

Thanka a lot. That link was very helpful.

I’m having the same issue with video background…not working in rails app… any new solutions for this problem?