I have a rails '4.2.11.1' application. I want to dissable assets compilation, minifying, pipeline in development. in order to use indium debugger
The rails app seems to be set up with sprokets. so in my config/application.rb I changed to this:
# Enable the asset pipeline
config.assets.enabled = false
also in config/environmetns/development.rb I have this setup:
# Do not compress assets
config.assets.compress = false
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
config.serve_static_files = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
but nothing happens and I get the files:
assets/stixs.self-7246a54effa0c5edaa806b9c4fbc6ba4617c0d80bef8c236f9a4cbcfcf7f0be7.js
finally I get this files not minifyed, or compresed but how can I get that rails work with serving the files in app/assets/javascripts in de delopment environment
Technique Sprockets uses for fingerprinting is to insert a hash of the content into the name
Add this in your development.rb
config.assets.digest = false
I hope that work for you.
On the development environment (with therubyracer) all works great. Now I set nginx + passenger to run my rails app for the production environment. All works fine except one (slides_index.js) file for which I get 404.
That file contains jQuery code which has to be run just on one page.
To do so I use <%= javascript_include_tag "slides_index" %> on that page.
I run rake assets:precompile which created public/assets/application-1774b3421bf0b4433ea3628c1c5dce38.js. There is no any other .js file in the that path, especially no slides_index.js (that one is in app/assets/javascripts/).
It's quite obvious that if there's not slides_index.js in the public/assets/ path than I get 404 for it. The question is why it works fine with therubyracer (development environment) and how to fix it in a proper way ?
By default Rails only compiles application.js as a standalone file. You can add other files to be compiled in config/application.rb with config.assets.precompile, so add the slides_index:
config.assets.precompile += ['slides_index.js']
I'm working on a Rails 4.0 app with following directory structure
-app
|->javascript
|->page-specific
|->myjavasript.js
In my application.css I have removed required tree directive to make sure I don't include all js on every page.
//= require_tree .
Now to include my javasript I used following syntax on my page:
The application works fine on my development environment but when I push my changes to my production environment, I get 404 when I browser make a call to get javascript.
I call made in production is:
server-name/javascripts/page_specific/myjavasript.js
I call made in develop machine is:
server-name/assets/page_specific/myjavasript.js?body=1
I read a bit about asset pipelines and added following to my production.rb:
config.assets.precompile += ['page_specific/myjavasript.js']
But still my public\assets folder doesn't contain myjavasript.js, and keep on getting a 404.
I have a couple of questions, I do I add page specific (not-cpntroller specific) assets to my app?
Why is it working on development and not in production, what is done differently?
How can I fix it?
In firebug I see:
"NetworkError: 404 Not Found - https://my-server/javascripts/page_specific/myjavasript.js"
Just try,
config.assets.precompile += ["page-specific/*"]
Then, open up rails console and run the below line to know whether page-specific folder is there under your app asset paths:
Rails.application.config.assets.paths
Hope it helps :)
I have a javascript in the vendors/assets/javascripts folder, and I have this line of code:
<script src="assets/grid.js"></script>
in one of my app/views page.
This grid.js file (inside the vendors directory) works when I test it out in localhost, but when I precompile and push my application to heroku, it says:
GET http://www.domain.com/assets/grid.js 404 (Not Found)
Why is this occurring?
Thanks
I would use the javascript_include_tag instead and that should work
<%= javascript_include_tag("grid.js") %>
In production I believe that the asset pipeline adds a hash onto the name of grid.js for fingerprinting (Section 1.2 of that documentation) so you can't use that path <script src="assets/grid.js"></script>
I tried: Set config.assets.compress = true in my config/environments/production.rb and all was fine, but it is a bad practice and gain bad performance. Yo can see this for more details config.assets.compile=true in Rails production, why not?
My solution:
Run in your local project RAILS_ENV=production bundle exec rake assets:precompile and push all the files generated in public/assent/ in your github repo and deploy in heruko. Yo can read this for more details https://devcenter.heroku.com/articles/rails-asset-pipeline#compiling-assets-locally
In order to debug javascript in my heroku production environment, I need to disable asset compression (or at least compression of javascript). I tried config.assets.compress = false along with config.assets.debug = true, and the compressed assets were still used. I then deleted the compressed assets, at which point no assets were rendered at all. I added config.assets.enabled = false, which did not help. I tried copying the uncompressed assets into various directories, including the application root, public, and public/assets (the latter two using both the folders "images, "javascripts", and "stylesheets", and putting the assets directly into the folders without the three subfolders). I was eventually able to get the javascripts to work by changing the html to directly reference all of the javascript files. But the CSS and images still are not working.
I would have thought that my original config.assets.compress = false should have worked. Any ideas what I did wrong?
I came up with this workaround after reading the docs:
create a module that does nothing to compress js / css here: lib/modules/no_compression.rb
class NoCompression
def compress(string)
# do nothing
string
end
end
configure your assets to (not) be compressed with your do-nothing compressor
config.assets.compress = true
config.assets.js_compressor = NoCompression.new
config.assets.css_compressor = NoCompression.new
Under Rails 4 just commenting out the line
# config.assets.js_compressor = :uglifier
in config/environments/production.rb worked for me. Looks like default is no compresson.
I also need to debug my js so I tried ncherro's solution. The problem was that it would still throw
rake aborted!
uninitialized constant NoCompression
So I just put the NoCompression class in the production.rb file
# Compress JavaScripts and CSS
class NoCompression
def compress(string)
# do nothing
string
end
end
config.assets.compress = true
config.assets.js_compressor = NoCompression.new
config.assets.css_compressor = NoCompression.new
Comment out the uglifier and add config.assets.debug = true. This worked for me.
Compress JavaScripts and CSS:
config.assets.js_compressor = :uglifier
Debug mode disables concatenation and preprocessing of assets. But this option may cause significant delays in view rendering with a large number of complex assets:
config.assets.debug = true
Also worth noting... In addition to ncherro solution you will need to do the following:
make sure to put your new module somewhere where it will be loaded by default. Was lib/extras in my case.
run rake assets:clean to clean your existing assets.
run rake assets:precompile to compile your assets using the new compressor.
restart your app... i use touch tmp/restart.txt
Happy debugging ;)
With Rails 4 on Heroku you need to do two things. First as #geekQ mentioned, comment out the js_compressor line in config/environments/production.rb
# config.assets.js_compressor = :uglifier
Second, you need to consider Heroku's asset pipeline cache for Rails 4. Any file with the same MD5 as the version in the cache will not be recompiled. The previous (possibly compressed) version will be served. Any file you edit will have a new MD5 and be recompiled.
You can also purge the entire asset cache with the Heroku Repo plugin to the Heroku toolbelt. Install that, then use the command
heroku repo:purge_cache
Deploy a new version after purging the cache and all your assets will be recompiled.
I had to update Rails.application.config.assets.version in config/initializers/assets.rb for the production.rb changes to take effect.
Find and comment out these line in environments/production.rb:
config.assets.js_compressor = ...
config.assets.css_compressor = ...
Looks like this MAY have been a bug in Rails. From the changelog for upcoming rails 3.2.9, is this what you were running into?
Respect config.digest = false for asset_path
Previously, the asset_path internals only respected the :digest option, but ignored the global config setting. This meant that config.digest = false could not be used in conjunction with config.compile = false this corrects the behavior.
http://weblog.rubyonrails.org/2012/10/29/ann-rails-3-2-9-rc1-has-been-released/
Do you think that could be related?