Asset Pipeline

Tips and Tricks

Brought to you by ninefold.com

@mookiy

٩(●˙▿˙●)۶

Tip #1: Don't do this

Dev 

$ rails s
http://localhost:3000

Deploy to Prod

Tip #2:

Test Locally in Prod

It really is that important!

Local Prod

$ rails s -e production
http://localhost:3000
$ RAILS_ENV=production rails s

Trick #1:

Get Local Prod working

Differences

Dev

Prod

conf../env../development.rb
config.assets.compile = true
conf../env../production.rb
config.assets.compile = false

Compiles on the fly

conf../env../development.rb
config.assets.compile = true

Assumes precompilation

$ git checkout -b test-prod
$ RAILS_ENV=production bundle exec rake assets:precompile
$ rails s -e production

What happened?

config/environment/production.rb
config.serve_static_assets = true

TO THE RESCUE!

$ rails s -e production

BOOM

Trick #2:

CSS and Images

I really don't like you, CSS...

background-image: url(“/assets/pic.jpg”);
background-image: url(<%= asset_path 'pic.jpg' %>);
background-image: image-url("pic.jpg");
background: image-path("pic.jpg");

Tip #3:

For Rails 3.2.x users

gem 'turbo-sprocket-rails'

Risa

@mookiy

Asset Pipeline Tips and Tricks

By rbatta

Asset Pipeline Tips and Tricks

Lightning talk for RockyMtnRuby 2014

  • 701