How do you catch errors in the rail resource pipeline before production?

I just get acquainted with Rails 3.1, and I burned for a while, updating an old project and trying to understand how the new asset pipeline in development mode behaves compared to production.

The default config.assets.precompile means only application.css and application.js , with the intention that everything should be used as one stylesheet and one javascript file.

Obviously, there are situations when we do not want this, so we can add items to the list in this configuration variable ...

Here is the situation that I encountered with my sandbox project when I went into production:

  • I looked at the site in development, saw that everything was working. Assets were linked as separate files, and the site displayed correctly.
  • I uploaded the site to my server and tried to make it work in production. The first error was that "ie.css" (conditional stylesheet) is not precompiled. (I was in Safari, and this stylesheet was not even loaded: the error was raised with the stylesheet_link_tag helper before the page was displayed.)
  • Ran rake assets:precompile and tried again.
  • Added an offensive element to config.assets.precompile and tried again.
  • The error is corrupted until another asset fails.
  • GOTO 3.

Not knowing how to solve this, I went around in circles several times until I thought that I had all the assets and the site was rendering in production. Then I tried it in MSIE and hit another 500 error: "belated_png_fix.js" was conditionally loaded, and until then it had not been displayed.

So my question is: besides trial and error or a strong dependence on integration testing, how can I predict that my site is not going to bomb when the asset pipeline detects that some stylesheets or javascript have not been added to the precompilation list?

I am also wondering why the missing element in the stylesheet should cause the whole page to be a 500 error, and not just compile it on request or serve 404 when this asset is requested. Is this a deliberate design "sooner or later"?

+8
ruby-on-rails asset-pipeline
source share
4 answers

I just released a gem called assets_precompile_enforcer , which ensures that developers don't forget to add assets to config.assets.precompile as they evolve. An exception will be raised if you enable the asset through javascript_include_tag or stylesheet_link_tag , and it does not match the filter in config.assets.precompile.

This means that asset errors will be detected during development, and not detected after deployment to production.

+2
source share

I had similar problems with rails 3.1. The best you can do is install the multi-stage capistrano stage and get an intermediate server.

If for some reason this is not possible, install the virtual machine on your computer and try to replicate your server environment.

+1
source share

Continuous deployment is a great thing, and you have to get to the point where it’s so simple that it’s not really so painful. At the same time, config.assets.precompile can accept regular expressions, so how about you come up with a standard for “explicit” top-level star files or a standard subfolder for things that won't be combined? (note that I have not tried this yet ...)

+1
source share

It may be redundant, but it works for me (it gives me clean, compiled assets). I have this in my .bash_profile file.

 alias ggo='bundle exec rake assets:clean && bundle exec rake assets:precompile && git add . && git commit -m "precompile" && git push origin master && cap deploy' 

and this is in my configuration / environments / production.rb (compiles compulsorily if necessary, not necessary if I do not run ggo first):

  config.assets.compile = true 

So my workflow: 1. code 2. git add and git commit 3. If I touch the CSS / SASS / JS / CoffeeScript files, I run ggo. Otherwise, I deploy the regular shell.

0
source share

All Articles