I'd like to run the task
assets:precompile
with compression in development environment.
I've set
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
in development.rb.
But compression with assets:precompile only seems to work in production mode, is that right?
Michael Kastner
For file compress in rails try this following method it will work exactly
My config/environments/development.rb has this, which I interpret the rails guide to mean that assets should be compiled into one file, but not compressed:
`config.assets.compress = false
config.assets.compile = true
config.assets.digest = false
config.assets.debug = false`
Try to add debug: false to your include/link-tags
It work means please
{# in views/layouts/application.html.haml (or .erb, then use <%= %>)}
= stylesheet_link_tag "application", debug: false
= javascript_include_tag "application", debug: false
No need to restart app! I hope you didn't forget to do it after you had changed your development.rb ;-).
Related
My rails app (v 5.2.4.1) works perfectly in local with config.assets.compile = true.
All the assets (images, js etc) are correctly loaded.
It works too in production with the same config (but it's very slow...)
So i read here config.assets.compile=true in Rails production, why not?
that it's a better way so set config.assets.compile = false in production
config.assets.compile = false
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.css_compressor = :sass
config.assets.debug = false
config.assets.digest = true
config.public_file_server.enabled = true
After set to false I made this command
RAILS_ENV=production rake assets:precompile (all the assets are generated in public/assets on Heroku)
i restart the server but all images are lost and .js are not loaded ?
Where is my mistake ?
We're coming off of using the asset_sync gem for managing our assets. I'm trying to setup the Asset Pipeline using these settings.
development.rb
config.assets.debug = true
config.assets.compile = false
config.assets.digest = true
config.cache_classes = true
config.eager_load = false
application.rb
config.assets.enabled = true
config.assets.css_compressor = :sass
config.assets.js_compressor = :uglifier
config.assets.version = '1.1'
I'm precompiling in Development and the assets are going into the public directory (hashed asset for each file). When using the stylesheet_link_tag, it works perfectly if I refer to the hashed asset directly:
stylesheet_link_tag("/assets/branding/visit/skin-295511b052d49d541763f276ddcf4efc.css")
But I need to be able to just call skin.css and be served the correct hashed skin.css file. I currently get a 404 with this:
stylesheet_link_tag("/assets/branding/visit/skin.css")
Is there a setting I'm missing to point to the hashed asset? Thanks for any advice.
Tech Specs
Ruby: 2.3.1
Rails: 4.2.7.1
I use bootstrap-sass to display glyphicons, it works well at localhost under development, but after i deploy it to a server use production, it display as a little square.
I have already search for answers, they just tell me to precompile something. But they didn't work.
This is my production.rb
OperationBackend::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.assets.precompile += ["*.woff", "*.eov", "*.svg", "*.ttf"]
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
Paperclip.options[:command_path] = "/usr/local/bin"
end
I also try make config.assets.complie = true
and do RAILS_ENV=production rake asset:precompile but they all didn't work
This problem torture me hours! Wish to got help from you guys!
config.assets.compile = true
should help
This did it for us. The glyphicons are in the vendors folder, so this is what we had to do to get them to work.
For some reason this worked for our production environment, but not our staging. Our staging.rb file is exactly the same as the production.rb file so this is quite the mystery.
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
config.assets.precompile << lambda do |filename, path|
path =~ /vendor\/assets/ && !%w(.js .css).include?(File.extname(filename))
end
We've just deployed a Rails 4.0.3 app to production and have found that asset paths generated by stylesheet_link_tag and javascript_link_tag are missing their fingerprints. So instead of requesting something like application-c841bd1c82c25bb1de8452d2338479f7.js, the page is just request application.js.
RAILS_ENV=production bundle exec rake assets:precompile is successful and generates fingerprinted files.
The bits from config/environments/production.rb that seem relevant are:
# 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
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
This is running on our own Apache server, not Heroku. I've looked around quite a bit and found similar problems, but none of the troubleshooting steps for those are helping here. Thanks.
More Information
In case it is helpful, here are the full contents (commented lines removed) of our config files:
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Ctrc
class Application < Rails::Application
config.ceal.application_title = "CTRC Budgeting"
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.assets.enabled = true
config.assets.version = '1.0'
config.pmacs_redmine.project_identifier = 'itmat-gcrc'
config.app_data_path = '/data/web/apps/itmat/ctrc'
config.paperclip_defaults = {
path: "/data/web/apps/itmat/ctrc/:attachment/:id/:style/:basename.:extension"
}
if ENV['RAILS_RELATIVE_URL_ROOT']
config.assets.prefix = ENV['RAILS_RELATIVE_URL_ROOT'] + '/assets'
end
end
end
production.rb
Ctrc::Application.configure do
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 = false
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.eager_load = true
end
I know that the application is running in production mode because if I set
config.assets.compile = true
in that file, the CSS and JavaScript are compiled and requested correctly.
I'm including those assets in the page like so:
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
but it is still generating links to those assets like this:
<link href="/apps/itmat/ctrc/stylesheets/application.css" media="all" rel="stylesheet">
<script src="/apps/itmat/ctrc/javascripts/application.js"></script>
instead of the fingerprinted links I would expect to see.
I had a similar issue and it turned out to be a problem with the gem AssetSync. Either setting config.assets.compile = true or removing the gem resolved the issue. Compiling assets on the fly and having your Rails serve your assets might be acceptable if you're using a CDN, but generally, taking another approach is usually recommended.
For rails 4.x be sure to set the following:
config/application.rb
config.assets.enabled = true
config.assets.version = '1.0'
config/environments/production.rb
config.assets.compile = false
Something always seems to go wrong when deploying an app to heroku, today its my images not being rendered.
I ran
rake assets:precompile RAILS_ENV=produciton
committed changes and pushed to heroku
In my view for example i have
<%= image_tag('/assets/logo.png') %>
but the image is not being rendered because its looking for logo.png as opposed to
logo-321321327454547676576586876.png
which was generated when running the precompile.. I think im missing an option in my production.rb file somwhere
Rails.application.configure do
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
How do i get the app to look for the generated image url created when precompiling? something simple Im guessing
I am going to use an S3 bucket to serve these in the future but am interested in getting it working with Heroku on its own
Thanks
After reading the api docs in more detail and taking Baloo's advice the answer is really simple, just a syntax issue with my path declarations
If your image is under assets just use
<%= image_tag('image.ext') %>
and if its in a sub directory then use
<%= image_tag('sub-dir/image.ext') %>
Hope this helps someone else