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

916 views
Skip to first unread message

Kranthi Kumar

unread,
Feb 16, 2016, 7:11:45 AM2/16/16
to rubyonra...@googlegroups.com
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.

--
Posted via http://www.ruby-forum.com/.

Justin Yoon

unread,
Feb 16, 2016, 10:19:59 PM2/16/16
to rubyonra...@googlegroups.com
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).

Kranthi Kumar

unread,
Feb 17, 2016, 3:11:42 AM2/17/16
to rubyonra...@googlegroups.com
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.

Bigos

unread,
Feb 17, 2016, 2:07:49 PM2/17/16
to Ruby on Rails: Talk
It will not work like this on Heroku

read this and make sure you did everything right
https://devcenter.heroku.com/articles/rails-asset-pipeline

Kranthi Kumar

unread,
Feb 18, 2016, 5:44:19 AM2/18/16
to rubyonra...@googlegroups.com
Hi. I think I have followed everything mentioned in the above mentioned
post "https://devcenter.heroku.com/articles/rails-asset-pipeline".

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>

Colin Law

unread,
Feb 18, 2016, 5:54:39 AM2/18/16
to Ruby on Rails: Talk
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

Kranthi Kumar

unread,
Feb 18, 2016, 6:16:43 AM2/18/16
to rubyonra...@googlegroups.com
Tried many combinations with video_tag. Still it shows the same error.

Colin Law

unread,
Feb 18, 2016, 7:13:21 AM2/18/16
to Ruby on Rails: Talk
On 18 February 2016 at 11:16, Kranthi Kumar <li...@ruby-forum.com> wrote:
> 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

Justin Yoon

unread,
Feb 18, 2016, 2:10:06 PM2/18/16
to rubyonra...@googlegroups.com
> 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.

Kranthi Kumar

unread,
Feb 20, 2016, 3:43:56 AM2/20/16
to rubyonra...@googlegroups.com
Colin Law wrote in post #1181474:
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.

Kranthi Kumar

unread,
Feb 20, 2016, 3:53:40 AM2/20/16
to rubyonra...@googlegroups.com
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.

Colin Law

unread,
Feb 20, 2016, 4:27:04 AM2/20/16
to Ruby on Rails: Talk
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

Kranthi Kumar

unread,
Feb 20, 2016, 4:31:31 AM2/20/16
to rubyonra...@googlegroups.com
Colin Law wrote in post #1181533:
Great. Thanks.

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

Colin Law

unread,
Feb 20, 2016, 4:40:04 AM2/20/16
to Ruby on Rails: Talk
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

Justin Yoon

unread,
Feb 20, 2016, 4:25:32 PM2/20/16
to rubyonra...@googlegroups.com
> 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:
http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not.
Not sure how helpful it is but hopefully you'll get some answers out of
it.

Laith Shadeed

unread,
Feb 21, 2016, 11:23:37 AM2/21/16
to rubyonra...@googlegroups.com
[Sorry I hit send by mistake in previous email]

Hi Krfg,

Welcome to Ruby on Rails. I am alost got started last week. I setup my development box on ArchLinux and two days back on OSX. Generally speaking, whenever I started with new language or framework, I prefer to check the official docs as it is mostly the accurate one (which is you are already doing). For example:
  1. For RoR 4: http://guides.rubyonrails.org/getting_started.html#installing-rails
  2. For RoR 5 Best: http://edgeguides.rubyonrails.org/getting_started.html#installing-rails
I agree with you if sometimes you find official docs does not have enough details, usually because the writer already been doing this for a while and some small details becomes second habit for him/her. Please find my comments inline

On Saturday, February 20, 2016 at 3:33:34 PM UTC+1, krfg wrote:
Having finished the Michael Hartl Rails tutorial, which uses Cloud9 as development environment, I would like to redo it configuring my machine (Ubuntu 14.04 LTS) as a local development environment.

Thats awesome, doing it yourself is the best way to learn about something new. I respect c9 and all those other SaaS/PaaS services however configuring locally for learning is the best way. Sometimes you get frustrated when configuring something for the first time, I remember this happens to me every-time, for example two months ago when I was trying to install Gentoo from scratch.
 

I am determined to use Atom + Terminal, and I would really appreciate some help in determining what remains of all the necessary software to be installed in my computer, because the tutorial is not much helpful in this respect.

Atom is cool tool to start with and I guess you found your way in installing it. GUI Terminal is of course already installed (most of the time) .


Before Rails I decided to study some Ruby.
In the official Ruby web page, Bitnami RubyStack is recommended as a complete development environment for Rails. Since I planned to study Ruby for Rails, I installed Bitnami RubyStack: would you recommend to keep it? Or, as I suspect, it would be better to install each component separately?

I personally would install each component separately for learning and also because most of time such fat installers install things that you will not be using at least when you are getting started.


The official Rails web page used to provide a link for those interested in how to install the Ruby on Rails development environment: would that be a recommendable solution?

I checked this link, for ubuntu it is using a rails-install-ubuntu.sh which is just a shell script the automate running multiple commands. Again doing it yourself is better for learning, you can read the script and try to understand what each command does before executing that command manually.


Combining my brief experience as a student and The RailsApps Project suggestions, I suppose I need the following applications:
  • database: the Rails Tutorial uses SQLite but Heroku recommends to use PostgreSQL also in development (Heroku uses PostgreSQL). I am undecided because on the one hand I completed the course without noticing any incompatibility between SQLite and PostgreSQL, and Michael Hartl says that SQLite is much easier than PostgreSQL. On the other hand I do not know the limits of compatibility between the two databases, so I would not like to find myself into trouble.
It depends on what do you want to achieve. If you are just installing things to learn about RoR, then definitely go with  SQLite as it is easier to setup and satisfy the needs. If you are planning to build a production-ready application then the choice of database matters:
  1. SQLite: suitable for storing small things, could be configurations, or small apps where each user data is stored in separate SQLite file. Mostly you want to avoid SQLite for concurrence access for write due to locking will become a problem.
  2. Relational database like PostgreSQL or MySQL for bigger projects where you are looking for a trustworthy database than can serve even the scale of Facebook.
  3. NoSQL databases where you application model is less relational (note you will have to program the relation in the code) or the user perceived performance is really critical, although I could argue that you can still achieve comparable results with relational databases (of-course by using some more advanced techniques, or just extra hardware)
In short, if you are just learning go with SQLite.
  • RVM: will I need RVM for switching between Ruby versions? The RailsApps project recommends it. For the tutorial, it was more determinant the possibility to choose the Rails version than that of Ruby.
It is good to start with some version manager, because in many cases the default .deb package that you get from apt-get is not always the latest version due to 14.04 is considered a stable LTS version of ubuntu. I personally tried rvm & rbenv, I found it rbenv nicer, although it is just a matter of taste.
  • Bundler: is it installed with Ruby of will I need to install it separately?
  • Node.js: the RailsApps project says that "for development on Ubuntu Linux it is best to install the Node.js server-side JavaScript environment".
I am not sure why do you need Node.js here. If you are planning to do ReactJS or AngularJS (Single-Page-App) then anyway the regular rails way may not be the best, you will need to tweak things. For example in Rails 5, rails-api code got merged with the official release so that you can drop the 'view' part of your rails app and rely on ReactJS (for example) to give you the view. However if you are getting started with Rails, I suggest to stick with the default setup without the complexity of those awesome front-end frameworks because they are really a different story that you will need to learn at some point.
  • Web server: what local web server would you suggest? WEBrick? Apache? The tutorial uses WEBrick.
For development purposes, WEBrick (Rails 4) or Puma (Rails 5) is good enough. For production deployment you will need another solution like Unicorn or uwsgi. The idea is you need a web server that works well with the Rack web server interface, which is a concept used by other languages as well like Python and Perl. Sometimes also you add in front of that an nginx server. I will not go though more details as I guess is more about to deploy production setup.

In short for development locally and getting started stick with the default rails server WEBrick (Rails 4) or Puma (Rails 5)
,   
  • Git: Git is already installed with Ubuntu. Will that be enough?

Would you recommend anything else?
Finally, I suppose I will need to find documentation on how to configure all these applications: do you have any suggestion about that?

Many thanks in advance

To test setup on ubuntu 14.04 64 LTS. I installed a vanilla vagrant box. Here the commands I typed to get rails running:

# 1. Setup your locale, I assume the locales already working for you, you can skip this step
$  echo 'LC_CTYPE="en_US.UTF-8"' | sudo tee -a /etc/default/locale

# 2. Check if ruby installed
$ ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

As I mentioned before, the default ruby version is not the latest, so we could use version manager to get a latest version. You can also do that in other way by importing edge packages for a personal package archive (ppa), however using a version manager is more cool and easier. Although on production I believe you will need to use proper .deb package not a version manager installation.

# 3. Check if git installed
$ git --version
The program 'git' is currently not installed. To run 'git' please ask your administrator to install the package 'git'

# 4. Note that installing git from apt-get have the same problem as installing ruby because 14.04 LTS package repository only has stable packages 
# To install latest git version, you can compile from source code, or find a good ppa with latest git packages. I will go with ppa git-core
$ sudo apt-add-repository -y ppa:git-core/ppa 

# 5. Update apt local index
$ sudo apt-get update

# 6. Install git
$ sudo apt-get install -y git

# 7. Check git version again
$ git --version
git version 2.7.1
 

# 8. Installing rbenv, you can go via ppa path but it is not update to date, so I will go with compile from source.
# I will assume you have make and gcc installed, otherwise run sudo apt-get install -y build-essential
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
 
$ cd ~/.rbenv && src/configure && make -C src
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile && source ~/.bash_profile 
$ ~/.rbenv/bin/rbenv init

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile && source ~/.bash_profile  
Sorry I hit send by mistake. Once rbenv installed, you need the ruby-build plugin to tell rbenv how to build ruby version.
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

# 9. Now install ruby, first we need to make sure you have the tools to build the source code:
$ sudo apt-get install -y build-essential libssl-dev libreadline-dev zlib1g-dev
$ rbenv install 2.3.0
$ rbenv global 2.3.0 #Set this version globally
$ hash -r # to clear shell cache
$ rbenv version
2.3.0 (set by /home/vagrant/.rbenv/version)
$ ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.1
  - RUBY VERSION: 2.3.0 (2015-12-25 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0
  - USER INSTALLATION DIRECTORY: /home/vagrant/.gem/ruby/2.3.0

# 10. Install Rails, I will go with Rails 5 beta
$ gem install rails --pre
$ rails --version
Rails 5.0.0.beta2

# 11. Bundler, it does not come with default ruby installation:
$ gem install bundler
$ bundler --version
Bundler version 1.11.2

# 12. Install sqlite, note that you need libsqlite-dev to be able to build sqlit3 gem later while creating new rails app
$ sudo apt-get install -y sqlite3 libsqlite3-dev
$ sqlite3 -version
3.8.2 2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d

# 13. Create a project as in the manual 
$ rails new blog

# 14. Start the server 
$ cd blog && bin/rails server
/home/vagrant/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an
 error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)

# I was wrong previously, it seems we need nodejs to be able to execute uglifier. Uglifier is a tool used to minify javascript, it is written in javascript so to be able to run you will mostly need nodejs. Lets install nodejs via nvm

# 15. Install node version manager
$ source ~/.bashrc #assuming it writes things to bashrc
$ nvm --version
0.31.0

# 16. Install node itself
$ nvm install 5.6.0
$ node --version
v5.6.0

# 17. Try again to start rails server
$ bin/rails server
=> Booting Puma
=> Rails 5.0.0.beta2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server

# 18. Congratulations you a rails installation ready, good luck.

Colin Law

unread,
Feb 21, 2016, 11:38:09 AM2/21/16
to Ruby on Rails: Talk
On 21 February 2016 at 16:22, Laith Shadeed <laith....@gmail.com> wrote:
> [Sorry I hit send by mistake in previous email]

I fear this time you have replied to the wrong email.

Colin

Kranthi Kumar

unread,
Feb 24, 2016, 3:12:57 PM2/24/16
to rubyonra...@googlegroups.com
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:
>
http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not.
> 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.

Drew Lubz

unread,
Dec 28, 2016, 1:39:40 PM12/28/16
to Ruby on Rails: Talk
I'm having the same issue with video background...not working in rails app... any new solutions for this problem?
Reply all
Reply to author
Forward
0 new messages