문제

I am using Rails 3.1 and under assets I have files like this:

assets
  javascripts
    admin
        admin.js
        a1.js
    client
       client.js
        c1.js

admin.js looks like this

//
//= require jquery
//= require jquery_ujs
//= require a1

client.js looks like this

//
//= require jquery
//= require c1

Everything works fine in development mode. When I do rake assets:precompile then I do not see any javascript files in public/assets. I do see all the stylesheets in public/assets.

I think this has to do with the fact that manifest files (admin.js and client.js) in this case are in subdirectory.

So is this true that rake assets:precompile does not look into subdirectories?

Any suggestions on how to fix this. I prefer to have the files the way I laid out because I have a bunch of javascript files.

도움이 되었습니까?

해결책

There is a precompile array in the Rails config that sets what files to precompile. application.js and application.css in any directory.

You will need to add your files to the precompile array:

config.assets.precompile += ['admin/admin.js', 'client/client.js']

And they should be accessible via:

javascript_include_tag "admin/admin.js"

and

javascript_include_tag "client/client.js"

다른 팁

At rails 3.2.6, when managing javascript assets in subdirs, you can name the manifest for each subdir 'index.js' (as opposed to OP's 'admin.js' and 'client.js'), and then in config/environments/production.rb say:

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

Magic behind the scenes will look in the admin subdir and compile according to the specs in index.js, outputting to admin.js; likewise for client.

The assets will then be accessible via:

javascript_include_tag 'admin'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top