Questions tagged [sprockets]

Sprockets is a Ruby library that preprocesses and concatenates JavaScript and CSS source files.

Sprockets takes any number of source files and preprocesses them line-by-line in order to build a single concatenation.

Specially formatted lines act as directives to the Sprockets preprocessor, telling it to require the contents of another file or library first or to provide a set of asset files (such as images or stylesheets) to the document root.

Sprockets attempts to fulfill required dependencies by searching a set of directories called the load path.

807 questions
389
votes
29 answers

Using Rails 3.1, where do you put your "page specific" JavaScript code?

To my understanding, all of your JavaScript gets merged into 1 file. Rails does this by default when it adds //= require_tree . to the bottom of your application.js manifest file. This sounds like a real life-saver, but I am a little concerned…
378
votes
14 answers

How can I disable logging of asset pipeline (sprockets) messages in Ruby on Rails 3.1?

Sprockets tends to be quite verbose in the (dev) log by default under Ruby on Rails 3.1 (RC1): Started GET "/assets/application.css" for 127.0.0.1 at 2011-06-10 17:30:45 -0400 Compiled app/assets/stylesheets/application.css.scss (5ms) (pid…
167
votes
3 answers

Using Rails 3.1 assets pipeline to conditionally use certain css

I’m in the process of building my first solo Rails app using Rails 3.1.rc5. My problem is that I want to have my site render the various CSS files conditionally. I’m using Blueprint CSS and I’m trying to have sprockets/rails render screen.css most…
talon55
  • 2,023
  • 3
  • 15
  • 10
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
73
votes
1 answer

Access Asset Path from Rails Controller

I'm sharing a configuration yml file client side, that I need to also load on the server side, I've placed it inside app/assets/javascripts/configuration.yml I can use #{asset_path 'configuration.yml'} inside a view to get the path, but I can't…
Marcel M.
  • 2,376
  • 2
  • 18
  • 24
60
votes
3 answers

What does require_self mean?

In rails3.1 application.css we could see /* *= require_self *= require_tree . */ I know that require_tree . is just telling the system to bundle together everything from the stylesheets folder into a single file. But what does require_self tells?
kriysna
  • 6,118
  • 7
  • 30
  • 30
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
4 answers

After gem update: test fail with "Asset was not declared to be precompiled in production"

Since I updated several gems all tests fail with the error: ActionView::Template::Error: Asset was not declared to be precompiled in production. Add Rails.application.config.assets.precompile += %w( favicons/manifest.json.erb ) to…
Marty
  • 2,132
  • 4
  • 21
  • 47
50
votes
5 answers

How do I use reference images in Sass when using Rails 3.1?

I have a Rails 3.1 project with the asset pipeline working great. The problem is that I need to reference images in my Sass, but Rails calculates image URLs. (This is particularly important in production, where Rails appends the Git hash of the…
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
46
votes
4 answers

How can I get the Rails asset pipeline to produce source maps?

I'd like to have Rails produce source maps alongside the compiled coffeescript/minified JS, for better error logging. There doesn't seem to be comprehensive documentation on the net on how to do this, yet, though. Has anyone done this? I'm on Rails…
Vincent Woo
  • 2,650
  • 1
  • 20
  • 21
43
votes
5 answers

Rails 3.1 Sprockets require directives - is there a way to exclude particular files?

If I'm using //=require_tree . in application.css, is there a way to exclude particular files other than resorting to //=require_directory and tree organization? Perhaps something like //= require_tree ., {except: 'something'}
tamersalama
  • 4,093
  • 1
  • 32
  • 35
41
votes
5 answers

Rails 3.1 is very slow in development-mode because of assets, what to do?

After I added Sprockets, Rails is loading very slow in development mode, what should I do to speed it up?
jonepatr
  • 7,769
  • 7
  • 30
  • 53
39
votes
5 answers

require_tree argument must be a directory in a Rails 5 upgraded app

I just upgraded my app from Rails 4.2.7 to Rails 5.0.0.1. I used RailsDiff to make sure I had everything covered and I believe I did. So far everything has worked well up until the loading of my app. Now I am seeing this…
marcamillion
  • 32,933
  • 55
  • 189
  • 380
37
votes
2 answers

How to disable adding ".self." in Sprockets 3.0

Even if config.assets.digest = false is set Sprockets 3.0 keep adding .self. to all static files: application.css becomes application.self.css?body=1 How to disable adding self? It is needed for correct browsersync work.
Dmitrii Dushkin
  • 3,070
  • 4
  • 26
  • 37
1
2 3
53 54