Just to confirm, does running rake assets:precompile amalgamate all js and css files into application.css and application.js files under the public/assets directory? What is the purpose of this file? The reason I ask is because for some reason my development mode is running into a lot of asset loading conflicts with this file, but my production mode runs just fine. It seems that the only way I can get my application to serve assets properly in development environment is to delete these files.
Is there a configuration in my development.rb file that I can setup to prevent my application from relying on this file in development mode?
Using
rake assets:precompile:primary RAILS_ENV=production
instead of
rake assets:precompile
should prevent the assets without md5 being added to the public/assets directory - which should make sure the development mode assets are generated dynamically.
Quote
To stop the creation of the non-hashed filenames in public use:
rake assets:precompile:primary RAILS_ENV=production
from:
Why does rails precompile task do non-digest assets
Related
We're having a small issue with our app. Currently we've made an update of the internal design and uploaded to the server, however running the following;
RAILS_ENV=production bundle exec rake assets:precompile
only precompiles certain items into the asset folder under public directory. Anyone else ran into the problem like this with suggestion how to fix. We have everything set correctly in environments and initializers.
Sounds like some files are not getting into the precompile list. Try adding this to your config/application.rb
config.assets.precompile = [/^[^_]/]
This should be a catch all that will pick up all your js and css. Let me know if that works for you guys. Also you should be sure to tell that guy that you are listening to that deploying via FTP is silly.
My setup is fairly simple default rails 3.2.1 setup. All my .css.sass files are in /app/assets/stylesheets/. I have the sass-rails '~> 3.2.3' gem in :assets group.
There's no application.css, just main.css.sass (used for main layout).
When i issue:
RAILS_ENV=production bundle exec rake assets:precompile
it compiles my coffeescripts and javascripts. There are no error messages in the log. It's like it doesn't even try to compile sass files.
The main.css.sass file header looks like this:
//=depend_on "_globals.css.sass"
#import globals
The _glocals.css.sass exists in the same directory.
James is right and it's one of the possible solutions.
The drawback of adding all files to one manifest file is that all will be precompiled to single file - which isn't always what you want.
In my case I needed separate files (one file for each layout).
Heres how to add new manifest files:
config.assets.precompile += %w( file1.css file2.css )
You don't need to have actual file1.css, if you have file1.css.sass it will be precompiled.
I think sass needs a manifest file and by default that's application.css for a rails 3.2 app. So creating application.css and //= require 'main' might dove your problem.
I have created a rake task and I need to require a gem and two source files. I've used the bundle install to install the gem so that's not a problem, but what folder should I save my two source file to? My rake task in in /lib/tasks/my_rake_task.rb.
Under rails convention, should the source files be saved there as well or is there a preferred location. Thanks.
Looks like any file loaded in the lib folders is loaded.
Currently it seems Heroku is determined to pre-compile assets when I push my code up to my instances.
This is great for production servers, however for my "RAILS_ENV=development" server, this causes issues, as I now get pages with all the JavaScript files served up individually from my asset manifest, and then another file with the same code all grouped up as the pre-compiled asset.
This cause my jquery datatables libraries to break, throwing popup errors, which I don't get on my local environment (development or production) or in my production Heroku instance.
Is there anyway to disable pre-compilation of assets on Heroku for development mode instances ? Or is there any reason why these aren't already disabled on development Heroku servers already ?
If Heroku detect a public/assets/manifest.yml file then they will not attempt to precompile your assets and assume you are dealing with them yourself. More details at http://devcenter.heroku.com/articles/rails31_heroku_cedar
AFAIK, Heroku has to precompile assets to work around their readonly FS and the fact that the Rails asset pipeline wants to write files to the FS. The only thing I could suggest would be to work out why your assets are breaking when being compiled.
I worked around this by adding some voodoo to my Rakefile to disable the assets:precompile rake task.
first I add the user-env-compile labs component
heroku labs:enable user-env-compile
then add this to the beginning of my Rakefile
# found from http://blog.jayfields.com/2008/02/rake-task-overwriting.html
# used by conditional heroku asset compile magick
class Rake::Task
def overwrite(&block)
#actions.clear
enhance(&block)
end
end
Then I add this rake task in lib/tasks/disable_assets_on_heroku.rake
if ENV['RAILS_ENV'] == 'development'
namespace :assets do
task(:precompile).overwrite do
puts "Asset precompile skipped in #{ENV['RAILS_ENV']}"
end
end
end
I am struggling with the idea of deploying a large app using the the asset pipeline and the precompile Capistrano task.
I don't want to install the javascript runtime environment and precompile the assets on each production server.
The assets need to be uploaded to two Nginx servers that don't have a copy of the app.
So I have created a Capistrano task that precompiles the assets locally and then uploads the assets to the the Nginx servers, and the manifest files to the app servers.
The problem is the assets on my local machine could differ from the assets the git branch I am deploying from.
Is there a better way or must I just be dillagent to always deploy from the correct clean branch?
Edit here is the cap task that does the precompile and upload
namespace :assets do
after "deploy:update_code", "assets:precompile"
after "assets:precompile", "assets:upload_assets"
after "assets:precompile", "assets:upload_manifest"
desc "precompile assets"
task :precompile do
run_locally("bundle exec rake assets:clean && bundle exec rake assets:precompile RAILS_ENV=#{rails_env}")
end
desc "precompile and upload assets to webserver"
task :upload_assets, :roles => :nginx do
top.upload( "public/assets", "/usr/local/fieldphone/#{rails_env}/", :via => :scp, :recursive => true)
end
#
desc "upload manifest file"
task :upload_manifest, :roles => :app do
top.upload( "public/manifest.yml", "#{release_path}/public/", :via => :scp )
end
end
You say that assets on your local machines could differ from that on the deploy branch. In normal circumstances your dev environment doesn't need compiled assets.
That being so I'd suggest that you alter your task to remove the assets once they have been deployed, leaving your local working copy clean at all times. This would guarantee that each deploy gets the latest (correct) version of files. (If you are not doing so, I'd also suggest that you use the default options for dev mode which relies on Sprockets to do all the asset serving).
I don't think there's anything really wrong with committing the files to the repo and deploying that to the Nginx server - that's similar to the vendor cache for gems - it's redundant, but there for a reason.
Another option would be to actually deploy the app to your Nginx servers, and have Capistrano compile the assets there, but not start the app on those servers (create a Capistrano role for "assets" and deploy the app to it, but don't launch it on that role). This could get a bit messy...
As a last option, if you don't want to muddy the waters of your asset servers, or want to keep your options open for deploying assets somewhere else, you could have Capistrano git stash any unsaved changes first, checkout the master branch, and then compile the assets, upload them, remove them, checkout the previous branch (git checkout -), reapply the stashed changes (git stash apply --index), and continue! :)
Resources:
http://git-scm.com/book/en/Git-Tools-Stashing
Is there any way to git checkout previous branch?