miketucker
miketucker

Reputation: 1074

Rails 3.1 and Coffeescript: Require entire directory

There is a require for individual files like so:

//= require controllers/documents

Is there an equivalent for requiring a directory?

Upvotes: 4

Views: 8588

Answers (1)

Trevor Burnham
Trevor Burnham

Reputation: 77426

Yep:

//= require_tree controllers

By the way, you tagged this as coffeescript, but your question uses JavaScript comment syntax... so for the record, in CoffeeScript you want to use #=, not //=.

Also, this is actually a Sprockets question, not a Rails question. Sprockets is a default in Rails 3.1, but you can use it independently as well. At any rate, the Sprockets page offers documentation aplenty on require, require_tree, and many other handy directives.

Upvotes: 22

Related Questions