0

I develop a backbone application integrated with Rails.
My backbone application is under app/assets/javascripts/src, however I want to include it only in the admin namespace.

The problem is the last line of application.js include all javascript assets:

//= require_tree .

I would like to exclude the src directory. Is it possible?

guyaloni
  • 4,972
  • 5
  • 52
  • 92

1 Answers1

2

This can be done by writing a new manifest file and including it in all your admin pages. For example you can create an admin.js manifest file. Then make sure Rails compiles it by adding this to your application.rb:

config.assets.precompile += ['admin.js']

And then include it in your html files that are in the admin namespace with:

<%= javascript_include_tag "admin" %>

Make sure to not put require_tree within the admin.js file but rather only include files that are necessary for the admin namespace.


Documentation: http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

Ben Rudolph
  • 2,509
  • 2
  • 19
  • 26
  • Can you please refer me to the documentation? Would like to read more about it. – guyaloni Feb 14 '14 at 09:16
  • Updated with documentation link – Ben Rudolph Feb 14 '14 at 09:25
  • This is great but not enough. What I don't understand is how to prevent rails include all files under assets/javascripts. One thing is to create a manifest file in order to include the application where I need it, other thing is to avoid it to be included in all pages of the project. – guyaloni Feb 14 '14 at 09:49
  • 1
    See this: http://stackoverflow.com/a/9611240/835696 it's possible if you have the right version of sprockets. Otherwise you're kind of out of luck – Ben Rudolph Feb 14 '14 at 11:07
  • This is a nice one, thanks! It works for me, however it has one problem - looks like `stub` works with __files__ but not with __directories__... nothing is perfect :-( – guyaloni Feb 14 '14 at 11:42