rails 3.1.0 ActionView::Template::Error (application.css isn’t precompiled)

By default Rails assumes that you have your files precompiled in the production environment, if you want use live compiling (compile your assets during runtime) in production you must set the config.assets.compile to true. # config/environments/production.rb … config.assets.compile = true … You can use this option to fallback to Sprockets when you are using precompiled … Read more

Rails javascript only works after reload

For turbolinks 5.0 you must use the turbolinks:load event, which is called the first time on page load and every time on a turbolink visit. More info: https://github.com/turbolinks/turbolinks#running-javascript-when-a-page-loads CoffeeScript code: $(document).on ‘turbolinks:load’, -> my_func() JavaScript code: document.addEventListener(“turbolinks:load”, function() { my_func(); })

Heroku does NOT compile files under assets pipelines in Rails 4

Heroku’s asset plugins no longer work since Rails 4 does not support plugins. You need to use Heroku’s asset gems instead. Place this in your Gemfile: group :production do gem ‘rails_log_stdout’, github: ‘heroku/rails_log_stdout’ gem ‘rails3_serve_static_assets’, github: ‘heroku/rails3_serve_static_assets’ end Follow Heroku’s guide on getting started with Rails 4. Update (07/22/2013): Heroku now supplies a different gem … Read more

No route matches [GET] /assets

In production mode, Rails will not be responsible for serving static assets. Therefore, you are getting this error. Thin won’t do it either, since it’s just a wrapper around Rails. This is controlled by this setting in config/environments/production.rb in your application: config.serve_static_files = false Or in Rails 5: # config/environments/production.rb config.public_file_server.enabled = true Or set … Read more

Rails 3.1 asset pipeline: how to load controller-specific scripts?

To load only the necessary name_of_the_js_file.js file: remove the //=require_tree from application.js keep your js file (that you want to load when a specific page is loaded) in the asset pipeline add a helper in application_helper.rb def javascript(*files) content_for(:head) { javascript_include_tag(*files) } end yield into your layout: <%= yield(:head) %> add this in your view … Read more

How can I disable logging of asset pipeline (sprockets) messages in Ruby on Rails 3.1?

Place the following code in config/initializers/quiet_assets.rb if Rails.env.development? Rails.application.assets.try(:logger=, Logger.new(‘/dev/null’)) Rails::Rack::Logger.class_eval do def call_with_quiet_assets(env) previous_level = Rails.logger.level Rails.logger.level = Logger::ERROR if env[‘PATH_INFO’] =~ %r{^/assets/} call_without_quiet_assets(env) ensure Rails.logger.level = previous_level end alias_method_chain :call, :quiet_assets end end Updated: It now works for Ruby on Rails 3.2 too (previous attempt fixes before_dispatch, and now we’re going for the … Read more

Using fonts with Rails asset pipeline

If your Rails version is between > 3.1.0 and < 4, place your fonts in any of the these folders: app/assets/fonts lib/assets/fonts vendor/assets/fonts For Rails versions > 4, you must place your fonts in the app/assets/fonts folder. Note: To place fonts outside of these designated folders, use the following configuration: config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/ For Rails … Read more