Rails assets are cached even in Development - ruby-on-rails

Here is my Development.rb file
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.assets.digest = true
config.serve_static_assets = false
For some reason even in the development environment my CSS files are being cached and I can't figure out why

Was having similar issue: Javascript files were cached by the rails server
Solution (as mentioned by TheIrishGuy):
Stop Rails Server
$rake tmp:cache:clear
Start Rails Server
Crtl+F5 in the browser

Did you precompile any assets? If so check the public assets folder and remove.
Try clearing /tmp/cache/assets
Make sure the browser isn't caching the application.css, force refresh etc

Related

How to show unbundled individual javascript and css of my rails web-application

I want to show unbundled javascript and css of my web-application to a UI developer. I have tried adding require 'sprockets/railties'
config.assets.debug = true
in my production.rb, but it did not work and I can still see bundled, uglified css/js in my browser sources.
I tried running my production in development mode by adding rack_env development in my /etc/nginx/nginx.conf http block, but I get Bad Request due to following error:-
invalid number of arguments in "rack_env" directive in /etc/nginx/nginx.conf:16
Please help
Did you try purging and recompiling your assets by any chance? Depending on your deploy method, production assets may not be recompiled on every deploy / application start.
rake assets:clean (rake assets:clobber) for Rails 4+
rake assets:precompile
By default, config.assets.debug = true is what controls this 'bundling' behavior.
You might also try to comment out
config.assets.js_compressor = ... or
config.assets.css_compressor = ...
if you have any of those in your production.rb.
Another reason may be any sort of external cache, depending on where you host your app: Cloudflare or Heroku Asset Pipeline Cache (those usually cache based on MD5 of your assets).
And the last but not the least is... browser cache, just in case :)

Altering the files of a rails application without restarting the server

I have a rails application running on production environment on a remote server. Though the application is ready for use it is far from finished so it is going to be subject to changes in views, controllers and css files.
Is there a way to update one of those files and make the server aware of the change without having to stop it? I tried cleaning the caches on both server and browser side in order to force the application to regenerate them with no success.
In the production.rb file I have these options
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.log_level = :fatal
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
Thank you.
Have you considered versioning with Git? In a typical rails deployment, you would use something like git to version your software and then deploy with something like Capistrano so that you can push small changes up to a place like Github and then pull those changes in to your app via capistrano. There's a really great tutorial on how to do this on railscasts by Ryan Bates. Here's a link to Railscast #335.

rails no route matches after assets:precompile

I am running Rails 3.2.8 application in production mode.
I have routing problems after i have done "rake assets:precompile".
My log message is :
ActionController::RoutingError (No route matches [GET] "/corp/assets/application-cf24b2a92e88a02835248f85a9f3c462.css"):
This file exists and it is in current location.
My routes are under scope "corp".
My config "config/application.rb" have option "config.assets.enabled = true".
My config "config/environments/production.rb" have following options:
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
Application works fine in development mode.
Before that assets:precompile everything was fine.
After few hours of searching of posts i can't find any solution to my problem.
Please help me fix this!
In production mode, Rails will not be responsible for serving static assets. Therefore, you are getting this error. This is controlled by this setting in config/environment/production.rb in your application:
config.serve_static_assets = false
You can either set to that true or use a real server like Apache or Nginx which will serve the static assets. I suspect Pow may also do it.
Update
try this
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = false

Rails compiles assets both with and without md5 hash, why?

I'm relatively new to RoR and I'm curious about why Rails compiles assets both with and without md5 hash for production?
I run bundle exec rake assets:clean then bundle exec rake assets:precompile
My production.rb file:
MyApp::Application.configure do
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
config.assets.precompile += %w(tos.js, tos.css)
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
My application works with files with hashes in their names and it's the way it should be in my case :)
So I have two questions here:
1) Why is it happening when compiled?
Rails compiles assets both with and without md5 hash for production
2) What are these files (without hashes) for?
Maybe I don't get something, so please could someone explain.
The reason it does it is so that you can access the files without knowing the MD5 fingerprint (for example in a non-rails application, or a file within the rails app which isn't compiled or run by the rails stack (e.g. a 500/502 status error page). In this case you would have to compile the assets then change the css/js links in the static HTML files each time you updated the code (thus causing a change in the MD5 hash).
So instead rails produces 2 copies of each asset file, one with the fingerprint in the filename, the other without (e.g. application-731bc240b0e8dbe7f2e6783811d2151a.css, and application.css). The fingerprinted version is obviously preferred (see 'what is fingerprinting and why should I care' in the rails asset pipeline guide). But the non-digested version is there as a fallback.
As a final thought on the matter I'd take a read of the following pull request to the rails git repo: https://github.com/rails/rails/pull/5379 where they are discussing the pros and cons of the non-digested filenames, and the possibility of being able to turn off compilation of them.
HTH

Rails 3.1 Production - Javascript is missing .js endings on deployment

I've just made my Rails app and deployed it to Heroku. A very weird thing happened in the process though. Half of my javascript-files are missing their endings (.js). I have absolutely no idea why this is.I've searched far and wide, but I don't seem to find an answer.
My production-config looks like this:
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
config.assets.precompile << '*.js'
Any suggestions?
Posted this other similar question 1 hour ago (http://stackoverflow.com/questions/9049023/rails-3-1-production-javascript-loads-but-doesnt-execute). Sorry for the spamming.
Does this help? You didn't show where your js files are included. If they have dots in the name, apparently you need to tell Rails.
asset:precompile for .js files? rails 3.1

Resources