2 require tips for Rails 3.1 assets bundling with sprockets

Require and sass: if you use the variables or mixins, you should use the @import of sass instead of require. With require, each file is compiled separatly and then are bundled together. But if a variable is declared in one file, this declaration will not appear in the compiled CSS and so can’t be used in sass files that require this file. But, with @import, files are regrouped before the compilation and so you’ll avoid this problem.

Debug mode: when you are debugging Javascript, it’s annoying to have only one bundled file. For example, it’s hard to find the line where you want to put a breakpoint in firebug when you have several libs like jquery in this file. But Rails 3.1 has a solution for this specific problem: the debug mode. If you put :debug => true on the javascript_include_tag, each JS file will be loaded in a separate <script> tag. For our project, we use this line in our layout file:

<%= javascript_include_tag "application", :debug => Rails.env.development? %>

Two handy tips for using the asset pipeline in Rails 3.1.

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: