Questions tagged [asset-pipeline]

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass and ERB.

The asset pipeline is a feature added to Ruby on Rails 3.1 to provide improved organization and processing for JavaScript, stylesheets, and images. There also exists a Grails plugin named asset-pipeline that provides equivalent functionality to applications developed for this framework.

These assets can be separated into folders under app/assets/ for those that are application-specific, lib/assets/ for assets shared across multiple applications, and vendor/assets/ for third-party assets. Each of those folders would have subfolders like javascripts/, stylesheets/ and images/.

This is meant to eliminate what Ruby on Rails creator David Heinemeier Hansson calls the "junk drawer" approach of putting all JavaScript code (for example) in the same folder, regardless of source.

Additionally, as Ryan Bigg has documented:

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, SCSS and ERB. -- Rails Guides

3569 questions
77
votes
16 answers

Heroku does NOT compile files under assets pipelines in Rails 4

Everything goes well in local machine with assets pipeline in Rails 4 and Ruby 2.0. But when deploying to heroku, it is shown that: -----> Preparing app for Rails asset pipeline Running: rake assets:precompile I, [2013-03-12T03:28:29.908234…
aquajach
  • 2,548
  • 2
  • 23
  • 29
76
votes
6 answers

Rails 3.1 asset pipeline: how to load controller-specific scripts?

If I generate a new controller in Rails 3.1, also a javascript file with the name of the controller will added automatically. Firstly, I thought this javascript file will used only, when the related controller is called. By default there is the…
Mike Bevz
  • 1,266
  • 1
  • 14
  • 20
71
votes
7 answers

How to set a max-width as percent AND pixels?

How can I prevent the width of a div from expanding beyond a percent AND a pixel? In other words, the browser should calculate the pixel value of the percent, and then choose the lower of the two values. If I were to set them both like this:…
Joe Morano
  • 1,715
  • 10
  • 50
  • 114
70
votes
5 answers

Using a Rails helper method within a javascript asset

Is there any way to use a Rails helper method, more specifically, a path helper method within a javascript asset file. This file foo.js.coffee.erb $('#bar').val("<%= create_post_path %>") I would love it if I could get from…
axsuul
  • 7,370
  • 9
  • 54
  • 71
65
votes
7 answers

Confusion about rake assets:clean / cleanup on the asset pipeline in rails

Could somebody explain to me what the command rake assets:clean really does? Unfortunately the Rails Guides dont mention it. There is also the command rake assets:cleanup. Whats the difference? Furthermore could somebody tell me when do I have to…
daniel
  • 3,105
  • 4
  • 39
  • 48
65
votes
8 answers

How to use fonts in Rails 4

I have a Rails 4 application and I am trying to use a custom font. I have followed many tutorials on this and somehow it's just not working for my application. I am using application.css.less and have the following declaration: @font-face { …
SnareChops
  • 13,175
  • 9
  • 69
  • 91
65
votes
3 answers

How can you speed up the Rails Asset Pipeline precompile process?

What are the ways that you can speed up the Rails Asset Pipeline precompile process?
xdite
  • 1,669
  • 1
  • 12
  • 11
64
votes
5 answers

Clear the cache from the Rails asset pipeline

I'm starting a new project in Rails, and it looks like the application.js manifest file is doing something funny with the javascripts that I reference - does it cache those files as part of the asset pipeline? Here's what happened. I added a…
62
votes
3 answers

rails 4 asset pipeline vendor assets images are not being precompiled

I'm using rails 4 & ruby 1.9.3 for my application and fancybox2-rails gem, but there's a general problem with asset pipeline. If I run rake task for precompile, then everything is fine except for images in vendor/assets/images and…
banesto
  • 1,672
  • 1
  • 13
  • 13
60
votes
7 answers

Speed up assets:precompile with Rails 3.1/3.2 Capistrano deployment

My deployments are slow, they take at least 3 minutes. The slow Capistrano task during deploy is assets:precompile. This takes probably 99% of the total deploy time. How can I speed this up? Should I precompile my assets on my local machine and add…
Godisemo
  • 1,813
  • 2
  • 18
  • 26
58
votes
8 answers

Rails javascript only works after reload

The problem is exactly what the heading says. The javaScript is in the asset pipeline i.e assets/javascripts/myfile.js.coffee In the application.js I have: //= require jquery //= require jquery_ujs //= require turbolinks //= require…
Jason Carty
  • 1,247
  • 2
  • 13
  • 17
55
votes
4 answers

How to avoid precompiled assets being served in development mode?

I prefer not to concatenate JavaScript files in development mode, but serve them as individual files. So I configured: development.rb: config.assets.compress = false config.assets.debug = true config.assets.compile = true In my…
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
53
votes
2 answers

Rails asset pipeline: Standard way for including all /vendor/assets/javascripts/?

I've been transitioning an app to Rails 3.1 (and now on to 3.2) and watched the Railscast on the asset pipeline. I moved all of my third-party jquery plugin files to the /vendor/assets/javascripts/ directory. In my…
robertwbradford
  • 6,181
  • 9
  • 36
  • 61
52
votes
5 answers

Rails 3.1 asset pipeline and manually ordered Javascript requires

I am trying to convert an existing app to the new 3.1 asset pipeline layout, and want to include a lot of vendor files that have to be in a specific order, (underscore.js and backbone being one pair). As such, I can't just use a = require_tree . to…
beseku
  • 917
  • 1
  • 6
  • 12
52
votes
8 answers

Rails 3.1 and jquery-ui assets

This was asked in another question, but none of the solutions appear to work for me in 3.1rc1. I'm trying to use the new assets stuff in rails 3.1 - I have the files:…
Roman Gaufman
  • 1,104
  • 1
  • 13
  • 17