Open coli opened 10 years ago
Yes, there is a problem: when you add a new file app_assets.js
not updated. It is not associated with the cache Sprockets. Forced can reset it like this:
$ rm -rf tmp/cache
But the correct solution I have not found.
I have same problem
To automatically update app_assets.js
when adding new files in app/assets
, do the following steps. Add to Gemfile
:
group :development do
gem 'guard'
gem 'guard-shell'
end
Add to Guardfile
:
guard :shell do
watch(%r{^app/assets/.*}) { `rm -rf tmp/cache` }
end
Run the command bundle exec
to install the gems. Before starting to develop run guard
:
$ bundle exec guard
Warning! This may adversely affect the rate of return assets list in the development environment. Since they will be compiled at each change.
@kavkaz that fix doesn't work when you are deploying to a production environment (e.g. Heroku)
@jeremyhaile Production rails doesn't support changing assets without a reboot. Am I not understanding?
@kavkaz Could you review the following:
<%# Overrides app_assets.js.erb in js_assets gem %>
<% assets = JsAssets::List.fetch %>
<% assets.keys.map { |asset| depend_on asset } %>
window.project_assets = <%= assets.to_json %>;
window.asset_path = function(logical_path) {
return window.project_assets[logical_path];
};
That solved updates and deletes but I can't get Sprockets 2.x (Rails version) to monitor whole directories for adds. May have been fixed in Sprockets 3.0 by @josh.
This is what I really wanted:
<% assets = JsAssets::List.fetch %>
<% assets.keys.map { |asset| Pathname.new( asset ).dirname }.uniq.each { |path| depend_on path } %>
window.project_assets = <%= assets.to_json %>;
window.asset_path = function(logical_path) {
return window.project_assets[logical_path];
};
@mgenereu I tried your patch, but I'm getting the following crash:
couldn't find file '.' under '/Users/jeremy/projects/allynova/app/assets/javascripts'
crashing on this line:
<% assets.keys.map { |asset| Pathname.new( asset ).dirname }.uniq.each { |path| depend_on path } %>
Any updates on this bug? Has someone found a way to make it work on production
environments such as Heroku?
Seems like purging the build cache does the trick for Heroku. You can do this using Heroku CLI from your terminal as indicated here:
$ heroku plugins:install heroku-builds
$ heroku builds:cache:purge -a appname
You then need to make an empty commit and push it to invoke a new deployment.
A restart of the server is needed to get the new file detected. I believe this is due to the erb file being cached.