-1

If we include js/css files using application.css (like //=require_tree), then those files are working. But, I have stopped doing like that because it loads all js files of the project everytime.

So, I am adding (including) only required files per view basis. But they are not working when pushed to Heroku.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
user2139745
  • 1,721
  • 4
  • 19
  • 30
  • So... What's your question? Also, what's wrong with them always being included? – CDub Nov 22 '13 at 15:28
  • For example, I am getting this error - domain/javascripts/dropdown.js not found. But domain/assets/application-somestring.css is available. – user2139745 Nov 22 '13 at 15:31
  • Have you tried changing `domain/javascripts/dropdown.js` to `domain/assets/dropdown.js`? – CDub Nov 22 '13 at 15:32
  • Why not just use the asset pipeline? – CDub Nov 22 '13 at 15:33
  • You mean, require tree ? Lets assume I have 20 controllers, each one having its own js file. If I include using require tree, every page will be loaded with all those js files, sometimes raising errors in document ready , anyway, I am not sure about the best way. – user2139745 Nov 22 '13 at 15:34
  • And you tried this, yes? http://stackoverflow.com/questions/6167805/using-rails-3-1-where-do-you-put-your-page-specific-javascript-code – CDub Nov 22 '13 at 15:36
  • Including per controller in the sense, different urls will have different compiled application.js files. so, a single pre compile cant work. so what do you suggest? require_tree ? – user2139745 Nov 22 '13 at 16:07

1 Answers1

1

Including them on a per-view basis is not the right approach. First, you skip compilation (and thus you should store the assets in the public folder as static files), then you don't take advantage of the asset pipeline.

You can keep using the pipeline by splitting the assets in bundles and include only the bundle you want.

For example, you can remove the application.css file and split into alpha.css and beta.css, each file with its own includes. Add the files to the compilation in your production.rb file and you're done. Include those selectively, so that when you include alpha you will not load files included in beta.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • I am not talking about alpha and beta versions. Assume 4 pages, 3 of them requires each with its own js libs etc. this 4th page doesnt require any js. But, with require_tree, all those js files will be included in this page too...not sayng I dont like this, but asking if I can use requre_tree in this case too.. anyway thanks for the answer. – user2139745 Nov 22 '13 at 16:56
  • doing like this - not including application.js, but keeping all required base files in application.js, and including only controller.js. and keeping controller related js in controller_someconstant.js.coffee and in controller.js - including 'require application, require controller_someconstant . Is this a good approach? this solves my problem, but this is not working with gems(eg devise) which says sessions.js not found. – user2139745 Nov 23 '13 at 05:21