What is auto generating the assets folder in development environment? - ruby-on-rails

I am using rails 3.2.6 and my development.rb file has
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
and for some reason evertime i look in my public folder I have an assets folder that keeps appearing....I keep deleting it but it keeps reappearing ....is there a way to stop this
The main problem is the assets are being declared twice, once in the assets folder and once in the public folder which is an exact duplicate...this is messing things up for me

in application.rb
config.assets.enabled = false

Solved....I was my guard file compiling the assets
I commented out
guard 'rails-assets' do
watch(%r{^app/assets/.+$})
watch('config/application.rb')
end
And all is well

Related

Rails stylesheets placed in assets don't show on website

I have a set of custom stylesheets in assets/stylesheets/xxx folder.
I have a custom application_xxx.css.scss file in assets/ that requires all of those.
I have a custom layout xxx_application.html.haml which includes:
= stylesheet_link_tag 'application_xxx'
Everything works nicely in development, when I push everything now to the testing server none of the stylesheets are working. it gives a msg "Failed to load resource application_xxx.css "
Do I have to place my custom folder and custom application file in the public directory instead?
Have you precompiled assets?
bundle exec rake assets:precompile
You don't need to manually move any any custom css or js. Precompile your assets then try pushing again.
My production.rb file has these relevant lines:
config.assets.precompile += %w( application-all.css application-print.css )
config.assets.compile = false
config.serve_static_assets = false

Getting Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError

I have an image named pt_homepage_banner1.png.
I ran the task on production
bundle exec rake assets:precompile
and it successfully placed the image file into public/assets folder and made and entry into manifest.yml
Still i am getting exception -
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError
fpt_homepage_banner1.png isn't precompiled
My production.rb settings are
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
Please answer what i am missing. if any clarification regarding the question, please ask
Thank you
I also got the same error,
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError b-error.png isn't precompiled.
In my app I am calling this image, but in my images/ folder it was not there. So I added it and precompiled it again, so that the file appeared in public/assets folder. But I still gets the same error. So I know that Rails is somewhat stuck with this file, so what I did is I changed the b-error.png to 500.png and used another image and precompiled.
Now it Works!
Set following in config/environments/production.rb
config.serve_static_assets = true
config.assets.compile = true

How to make the asset pipeline process images in subdirectories

I have a Rails app that began as a 3.0.x app and recently was upgraded to 3.2.2. The images are in app/assets/images/ecommerce/new and when I run rake assets:precompile locally they aren't copied to public/assets/. However, when I copied all image files from app/assets/images/ecommerce/new to the root images asset path (that is, app/assets/imagens) and ran the rake task again, the images were all sent to public/assets.
When I run the server locally in production mode it doesn't find the images but when I deploy to Engine Yard, it does. That's very weird, do you know what's happening?
Can't the asset pipeline process images that are inside subdirectories of app/assets/images? Am I missing anything?
Here follows the source of config/environments/production.rb, on what concerns the asset pipeline:
MyApp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
config.cache_classes = 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 = true
config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif]
# Generate digests for assets URLs
config.assets.digest = true
config.assets.compile = true is the problem. This is not doing what you think it should. This actually tells the server to compile on demand. That might explain why you see the files sometimes, and other times you don't.
If you want to add directories, add them to config.assets.paths.

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 precompilation error in production for SWF file

I have a few .swf files that are being added to a project via a git submodule. They live in /vendor/private/widget/
To get the .swf files into the asset pipeline I'm doing the following:
config.assets.paths << "#{Rails.root}/vendor/private/widget"
In development this works just fine, but in production I get the following error:
ActionView::Template::Error (widget.swf isn't precompiled):
After searching around StackOverflow, I've tried these two solutions, both of which did not work:
config.assets.precompile << '*.swf'
config.assets.compile = true
Try setting application.rb 's
config.assets.digest = true
to
config.assets.digest = false
for the precompile, and flip it back to true afterwards. I don't know why this works or what part of the url digest would be preventing the asset inclusion, but this has been the only way i've found to be able to generate my assets in production to include swf files.

Resources