[LRUG] Rails 4 asset deployment woes

Tadas tadastamo at gmail.com
Mon Jul 15 05:03:43 PDT 2013


Hi,

some assets will not be included by default, you'll have to fiddle
with config.assets.precompile. Excerpt from a newly generated rails app
production.rb

   # Precompile additional assets.
   # application.js, application.css, and all non-JS/CSS in app/assets
folder are already added.
   # config.assets.precompile += %w( search.js )

See more: https://github.com/rails/rails/issues/9294

On Mon, Jul 15, 2013 at 12:54 PM, Jonathan del Strother <
maillist at steelskies.com> wrote:

> On 15 July 2013 12:45, James Coglan <jcoglan at gmail.com> wrote:
> > I'm struggling with getting asset deployment to work after upgrading a
> few
> > of our apps to Rails 4. I have two main problems:
> >
> > * We cannot reference images/fonts from stylesheets
> > * Our CSS/JS is no longer being minified in production
> >
> > The first one is because Rails no longer generates unversioned filenames
> in
> > public/assets, so you need to have
> >
> >     body {
> >       background: url(/assets/cat-abc123def456.jpg);
> >     }
> >
> > in your stylesheet rather than
> >
> >     body {
> >       background: url(/assets/cat.jpg);
> >     }
> >
> > Of course, the latter works in development but not in production after
> > precompiling the assets. So, we need to know how to get those version
> > numbers into the CSS, since Rails does not rewrite these references by
> > default while precompiling assets.
> >
> > Second, our CSS is not being minified, and we have no idea why. If you
> clone
> > https://github.com/jcoglan/rails_assets, and run:
> >
> >     $ bundle exec rake assets:precompile
> >
> > then it does not minify the code in public/assets, which we assumed was
> > because config/environments/development.rb sets config.assets.debug =
> true.
> > If you compile in production:
> >
> >     $ RAILS_ENV=production bundle exec rake assets:precompile
> >
> > then it does minify the CSS. So, we figured there must be a config
> > difference and that would explain why our code is not being minified in
> our
> > production apps that have been upgraded from Rails 3 to 4. So, I deleted
> all
> > the code from config/environments/{development,production}.rb and it
> still
> > does the same thing: no minification in development mode, and minified
> code
> > in production. So it doesn't seem like a config thing -- is this
> difference
> > baked in Rails? What am I doing wrong? Why would our production apps not
> be
> > minifying their CSS?
>
> Your stylesheets should be using the asset helpers to generate their
> paths.  eg -
>
>     body {
>       background: image-url("cat.jpg");
>     }
>
> should get automatically expanded to the full version-stamped path.
> See http://guides.rubyonrails.org/asset_pipeline.html#css-and-sass for
> more.
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>



-- 
Tadas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20130715/16b4f495/attachment.html>


More information about the Chat mailing list