Rails 4 Bootstrap 3 glyphicon display square under production - ruby-on-rails

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

Related

Rails 3.2.13 - Assets are not displayed in production

I've spent the whole day trying to figure out this issue, but without any positive results.
When I load my website, there are no CSS, images or working javascript.
The app is running on Rails 3.2.13 and Capistrano 2.
Here's my setup:
config/environments/production.rb
Appname::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.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.precompile = ['*.js', 'application.css', 'styles.css.scss', '*.css.erb']
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg *.woff *.ttf *.ico)
config.assets.digest = true
config.cache_store = :memory_store
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Apname
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/fonts"
config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
end
end
I ran locally bundle exec rake assets:precompile -> the files were generated to the public/assets directory.
But still -- there are no assets on production.
I have already no idea what to change in the config files, still the same result on the production server.
Every help will be warmly appreciated!
EDIT:
I just noticed in the console that images are loaded correctly (I can load http://website.com/assets/social_icons/facebook_ico.png), but not CSS+JS (http://IP/assets/application-3b6ba7703e465259e4e7ebee17c5ea1e.js 404 NOT FOUND - the same for .css)
Did you try to restart the webserver after compiling the assets?
Are the rights set correctly (chmod 755 . -R)?
Also, check that your webserver configuration points to app_root/public and not just app_root
EDIT1:
Check if you can load the url directly. In addition verify that the rendered page display correctly-cached urls.
If one of the two fails try forcing compilation for production environment
rake assets:precompile RAILS_ENV=production
EDIT2:
If nothing works try rolling back to default assets config for production:
# 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 = true
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
instead of:
#config.serve_static_assets = false
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.precompile = ['*.js', 'application.css', 'styles.css.scss', '*.css.erb']
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg *.woff *.ttf *.ico)
config.assets.digest = true
EDIT 3:
EDIT:
I just noticed in the console that images are loaded correctly (I can
load http://website.com/assets/social_icons/facebook_ico.png), but not
CSS+JS
(http://****/assets/application-3b6ba7703e465259e4e7ebee17c5ea1e.js 404
NOT FOUND - the same for .css)
That also means you aren't actually compiling assets. If you were, you'd need to load facebook_ico.png with the hash attached to the name

Rails 4, pushing app to Heroku, no CSS and no JS

I have pushed my rails 4 app to heroku, everythings works fine.
i have created a staging app by forking the original production app and i have named it "staging".
Now i have 2 apps: production and staging.
to have the same configuration I copied
config/environments/production.rb in config/environments/staging.rb .
i have pushed in heroku:
git push staging master
but the problem is in staging app i have no css and no js, but in production app i have both.
this is my production.rb file
#config/environments/production.rb
CentroservizirovigoCom::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
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
# 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
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end
Can you help me?

Rails HAML assets precompile with initialize_on_precompile false

I'm going a little nuts here.
I have 2 servers (heroku, same configuration) in 2 environments (staging, production).
Staging compiles my /assets/templates on demand and caches it without a problem.
Production serves the file uncompiled as html (being haml markup)
The problem is: the configuration of the 2 environments is identical (except mail server)
Gems, environment config and yml are the same.
Any ideas?
Update:
The haml assets where "precompiled" on both servers but raw. Staging didn't get the file missing and re-compiled because assets where compiled for production.
Now I'am stuck with adding haml to the asset compile pipeline with initialize_on_precompile false.
staging.rb / production.rb
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.static_cache_control = "public, max-age=2592000"
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.assets.precompile += %w( jquery.js modernizr+respond.js polyfills.js )
config.assets.precompile += %w( gp.js ad.js richmarker.js infobox.js )
config.assets.css_compressor = :yui
config.assets.js_compressor = :uglifier
config.assets.compress=true
config.threadsafe! unless $rails_rake_task
config.i18n.fallbacks = true
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get(ENV['LOG_LEVEL'] ? ENV['LOG_LEVEL'].upcase : 'INFO')
config.active_support.deprecation = :notify
config.action_dispatch.rack_cache = {
:metastore => Dalli::Client.new,
:entitystore => 'file:tmp/cache/rack/body',
:allow_reload => false
}
Haml::Template.options[:ugly] = true
Solution was to add the haml into the load. Add the following to application.rb
Sprockets.register_engine '.haml', Tilt::HamlTemplate

Rails 3.2 & assets pipeline: JavaScript Compression in development mode

Is it possible to serve compressed js in development mode in Rails 3.2? Gemfile contains
gem "closure-compiler"
and development.rb contains
config.serve_static_assets = true
config.assets.compile = false
config.assets.debug = false
config.assets.js_compressor = :closure
config.assets.compress = true
Have runned
RAILS_ENV=development bundle exec rake assets:precompile
And, even though the compiled application.js is there in:
./public/assets/application/application.js
./public/assets/application/application.js.gz
./public/assets/jasmine_rails/application.js
./public/assets/jasmine_rails/application.js.gz
... it never gets served.
This configuration made it work:
config.cache_classes = true
config.whiny_nils = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.compress = true
config.assets.js_compressor = :closure
config.assets.debug = false
config.assets.compile = false
config.assets.digest = true

JS and CSS files won't compress

I'm trying to compress my CSS and JS files in a Rails 3.1 application, without success.
The files won't get compressed.
Here is my production.rb file.
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.js_compressor = :closure
config.assets.css_compressor = :yui
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.assets.digest = true
I've also tried to run rake assets:precompile without success.
Anyone knows what the problem may be?
Found the source to the problem.
I had (for some reason) a manifest file inside the public dir that told the browser to fetch a non compress file.

Resources