Asset pipeline not working on Rails 3 project - ruby-on-rails

I am setting up a legacy Rails 3 project, ruby 1.9.3.
The asset pipeline is not working.
At this moment I have the following error:
ActionView::Template::Error (application.css isn't precompiled):
Here is my development.rb file:
MyProj::Application.configure do
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
config.serve_static_assets = false
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Do not compress assets
config.assets.compress = false
config.assets.compile = false
config.assets.debug = true
end
and here is my Gemfile
source "http://rubygems.org"
#gem 'pg'
gem 'mysql2'
gem 'rails', '3.2.3'
gem "authlogic", "3.0.3"
gem 'carrierwave'
gem 'rmagick'
gem 'fog'
gem "will_paginate", "~> 3.0"
gem "friendly_id", "~> 3.2.1"
gem 'activemerchant'
gem 'delayed_job_active_record'
gem 'i18n', '0.6.0'
gem 'ajaxful_rating_jquery', :git => "git://github.com/lshemesh/ajaxful_rating_jquery.git"
#gem 'acts_as_state_machine'
gem 'dynamic_form'
gem 'heroku'
gem 'jquery-rails'
gem 'state_machine'
#gem 'bartt-ssl_requirement', :require => 'ssl_requirement'
gem 'faker', '0.3.1'
gem 'populator', '0.2.5'
gem 'execjs'
gem 'daemons'
gem 'rack-ssl-enforcer'
gem 'braintree'
gem 'flag_shih_tzu'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
gem 'honeypot-captcha'
gem 'famfamfam_flags_rails'
gem 'language_list'
gem 'simple_captcha2', require: 'simple_captcha'
gem 'haml'
gem 'haml-rails'
# group :development do
# gem 'thin'
# end
group :production do
gem 'unicorn'
end
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'cucumber-rails', require: false
gem 'database_cleaner'
gem 'poltergeist'
gem 'factory_girl'
# gem 'autotest-rails'
gem 'factis'
gem 'email_spec'
end
group :assets do
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
end
I have the following on my application.rb
config.assets.enabled = true
# Add asset path to find our fonts
config.assets.paths << Rails.root.join("app", "assets", "fonts")
config.assets.paths << Rails.root.join("app", "assets", "javascripts")
config.assets.paths << Rails.root.join("app", "assets", "stylesheets")
config.assets.paths << Rails.root.join("app", "assets", "images")
And this is my application.css.scss
/*
*= require_self
*= require_tree .
*= require famfamfam-flags
*/
Any help?
Thanks

Related

rake aborted! Sass::SyntaxError: Undefined variable: "$alert-padding"

I got stuck on production environment for rails application because my assets are not compiled. When I use
rvmsudo bundle exec rake assets:precompile RAILS_ENV=production --trace
It throws rake aborted! Sass::SyntaxError: Undefined variable: "$alert-padding"
Here is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.2.3'
gem 'mysql2', '~> 0.3.11'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'sass-rails', '~> 5.0'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'haml'
gem 'haml-rails'
gem 'devise', github: 'plataformatec/devise'
gem 'html2haml'
gem 'simple_form'
gem 'validates_formatting_of'
gem 'tzinfo-data'
gem 'therubyracer', platforms: :ruby
gem 'twitter-bootstrap-rails'
gem 'jquery-validation-rails'
gem 'sprockets-rails', :require => 'sprockets/railtie'
gem 'jquery-turbolinks'
gem 'paperclip'
gem 'fancybox-rails'
gem 'css3-progress-bar-rails'
group :development do
gem 'spring'
gem 'pry-rails'
gem 'better_errors'
end
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
end
gem 'delayed_job_active_record'
# Need daemons to start delayed_job
gem 'daemons'
gem 'rails_config', '~> 0.4.2'
gem 'cancan'
gem 'two_factor_authentication'
gem 'twilio-ruby'
gem 'binding_of_caller'
gem 'rest-client'
Here is my porduction.rb
Rails.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_files = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = false
config.assets.compress = false
config.assets.digest = true
config.log_level = :debug
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.action_mailer.default_url_options = { :host => Settings.PROD_URL }
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
And application.css:
/*
*= require_tree .
*= require_self
*/
So, why i am getting rake aborted! Sass::SyntaxError: Undefined variable: "$alert-padding" while compiling.
My production works but no css is loaded to it.
$alert-padding variable is used before being defined. It may be caused by a wrong order of css files in application.css. require_tree loads all files from the current folder in alphabetical order (I guess), but you need some styles to loaded in specific order.
It seems like you're using bootstrap-sass gem. Consider the following instruction from the gem's README: https://github.com/twbs/bootstrap-sass#a-ruby-on-rails You need to rename application.css to application.scss and use #import instead of require.
Just add these lines in your config/application.rb if you are using scss instead of css.
config.assets.precompile << %w( *.scss *.js )
With SASS you have to include your variables before they're called.
Dir globbing / Sprockets include files alphabetically:
This has the problem that files are required alphabetically. If your directory has jquery-ui.js and jquery.min.js then Sprockets will require jquery-ui.js before jquery is required which won't work (because jquery-ui depends on jquery).
This means if you're using a variables.sass (or similar), you'll want to either rename it, or include it explicitly:
/*
*= require variables
*= require_tree .
*= require_self
*= stub variables
*/
Even better (since you're using SASS), use the #import directive:
#app/assets/stylesheets/application.sass
#import variables
#import *
I had a same issue
I just added this two lines in environment/production.rb
config.assets.compile = true
config.assets.precompile += %w( active_admin.css.scss )
It works for me.

How come helper.distance_of_time_in_words_to_now Time.now works in development but not production

I can call
helper.distance_of_time_in_words_to_now Time.now in development and it works just fine, but for some reason in production I am now getting translation missing: en.datetime.distance_in_words.less_than_x_minutes
What can I do to fix this?
Here is my gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.5'
gem 'pg', '0.17.1'
gem 'sass-rails', '~> 4.0.3'
gem 'coffee-rails', '~> 4.0.1'
gem 'uglifier', '>= 2.5.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem "bootstrap-sass", "~> 3.1.1.1"
gem "will_paginate", "~> 3.0.5"
gem "bootstrap-will_paginate", "~> 0.0.10"
gem "redcarpet", "~> 3.1.1"
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0.7'
group :development, :test do
gem "foreman", "~> 0.63.0"
gem 'annotate', '~> 2.6.3'
gem 'rspec-rails', '~> 2.14.2'
gem "guard-rspec", "~> 4.2.3", :require => false
gem "factory_girl_rails", "~> 4.4.0"
gem "guard-spork", "~> 1.5.1"
gem "spork-rails", "~> 4.0.0"
# gem 'spork-rails', github: 'sporkrb/spork-rails'
end
group :test do
gem 'rb-fsevent', '~> 0.9.4', :require => false
gem "growl", "~> 1.0.3"
# # Test gems for Linux
# gem 'rb-inotify', '0.8.8'
# gem 'libnotify', '0.5.9'
# # Test gems for Windows
# gem 'rb-fchange', '0.0.5'
# gem 'rb-notifu', '0.0.4'
# gem 'win32console', '1.3.0'
end
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
gem 'dotenv-rails'
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
gem 'unicorn', '~> 4.8.2'
gem 'unicorn-worker-killer', "~> 0.4.2"
# Authentication
gem "devise", "~> 3.2.4"
gem "cancan", "~> 1.6.10"
gem "geocoder", "~> 1.2.0"
gem "carrierwave", "~> 0.10.0"
gem "mini_magick", "~> 3.7.0"
gem "fog", "~> 1.22.0"
gem "unf", "~> 0.1.3" # for use with the fog gem
gem "validate_url", "~> 0.2.0"
gem 'psych', '~> 2.0.5'
gem 'paper_trail', '~> 3.0.1'
gem 'faraday', '~> 0.9.0'
# Use Capistrano for deployment
group :development do
gem "capistrano", "~> 3.2.1"
gem 'capistrano-rbenv', '~> 2.0'
gem "capistrano-bundler", "~> 1.1.0"
gem "capistrano-rails", "~> 1.1.0"
end
# Use debugger
# gem 'debugger', group: [:development, :test]
And here if my production.rb:
Example::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
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = 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.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
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Set to :debug to see everything in the log.
config.log_level = :info
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# config.assets.precompile += %w( search.js )
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Disable automatic flushing of the log to improve performance.
# config.autoflush_log = false
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# For devise
config.action_mailer.default_url_options = { :host => 'example.com' }
end
I figured out the problem. i18n gem version 0.6.10 was yanked, but I was using that in my system. As soon as I rolled back to 0.6.9 everything worked fine.

Rails4: How to serve gem specific javascript files?

I copied a working rails app into a different directory and renamed it using the rename Gem.
Most of the rails functionality works correct, but I am not able to serve assets bundled with gems specifically js files from bootstrap-slider-rails
I have compared my application.rb , Gemfile and application.js and they are the same in both apps.
I have tried uninstalling and installing the gem again
Simple comparison among the apps is not resolving issue.
Here are the files I have verified are same in both apps:
Gemfile
application.rb
application.html.haml
application.js
Any suggestions how I should debug this ?
Thanks!
Just to show you the issue, compare these 2 images in Rubymine
Working App:
Non working App:
Here is how some relevant files look like:
application.js
application.rb
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
#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
# Rails4
Bundler.require(:default, Rails.env)
module Smoothlyhired
class Application < Rails::Application
# don't generate RSpec tests for views and helpers
config.generators do |g|
g.test_framework :rspec, fixture: true
g.fixture_replacement :factory_girl, dir: 'spec/factories'
g.view_specs false
g.helper_specs false
end
config.autoload_paths += %W(#{config.root}/lib)
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password, :password_confirmation]
config.active_record.schema_format = :sql
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
#Prevent initializing the application and connecting to db on bootup as required by heroku
#https://devcenter.heroku.com/articles/rails-asset-pipeline
# Not required on rails4 anymore
#config.assets.initialize_on_precompile = false
#config.action_view.javascript_expansions[:defaults] = %w(jquery.min jquery_ujs)
end
end
Gemfile
source 'https://rubygems.org'
ruby '2.1.0'
gem 'rails', '4.0.0'
gem 'sass-rails', '~> 4.0.0'
gem 'coffee-rails', git: 'git://github.com/rails/coffee-rails.git'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'font-awesome-sass'
gem 'less-rails'
gem 'therubyracer', :platform=>:ruby
gem 'twitter-bootstrap-rails'
#gem 'jquery_mobile_rails'
gem 'js-routes'
gem 'cancan'
gem 'devise'
gem 'figaro'
gem 'haml-rails'
gem 'pg'
gem 'rolify'
gem 'sendgrid'
gem 'simple_form'
gem 'thin'
gem 'rake'
#To use db for storing cookies instead cookie-store
gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
group :development do
gem 'better_errors'
#gem 'binding_of_caller', :platforms=>[:mri_19, :rbx]
#Commenting out platforms part, because may be that's stopping this to be used on the dev machine'
gem 'binding_of_caller'
gem 'guard-bundler'
gem 'guard-rails'
gem 'guard-rspec'
gem 'html2haml'
gem 'quiet_assets'
gem 'rb-fchange', :require=>false
gem 'rb-fsevent', :require=>false
gem 'rb-inotify', :require=>false
# Required with Rails panel chrome extension. This Gem should come after better_errors gem
gem 'meta_request'
end
group :development, :test do
#gem 'factory_girl_rails'
#gem 'rspec-rails'
gem 'pry-byebug'
gem 'pry-stack_explorer'
gem 'pry-rails'
gem 'pry-debugger'
gem 'debugger', '>= 1.6.5'
end
group :test do
gem 'capybara'
gem 'database_cleaner'
gem 'email_spec'
end
group :production do
gem 'rails_12factor'
end
gem 'high_voltage'
#Linkedin Logins
gem "linkedin"
gem "omniauth"
gem "omniauth-linkedin"
gem "omniauth-facebook"
#postgres use hstore in active record
#gem 'activerecord-postgres-hstore'
gem 'state_machine'
gem "ruby-graphviz"
#payments
#gem 'stripe',:git => 'https://github.com/stripe/stripe-ruby'
#gem 'newrelic_rpm'
gem 'pgbackups-archive'
gem 'pg_search'
gem 'acts-as-taggable-on'
#gem 'activeadmin' , github: 'gregbell/active_admin'
gem "activeadmin", git: "https://github.com/gregbell/active_admin"
#gem 'kaminari'
gem 'bootstrap-slider-rails'
#gem 'twitter_bootstrap_form_for'
#gem 'bootstrap_form'
#gem 'formtastic'
gem 'formtastic-bootstrap'
gem 'rename'
Try deleting your gemfile.lock and running bundle install again.
Also refer to this SO post on copying and deploying rails apps. If you didn't, you should delete the .git file and run git init.
I'm not 100% sure this will fix your problem, but my suspicion is that you have gem issue.

loading page very slow because of missing jquery file in production mode

I use Nginx + Passenger + Rails 3 to run my website,
However, the page's loading time is too long.
I used the chrome inspector to see the problem, it showed me a jQuery file is missing ?
How could I solve it ?
Here's the Gemfile
source 'http://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'nokogiri'
# add will_paginate
gem 'will_paginate', '~> 3.0'
# Gems used only for assets and not required
# in production environments by default.
#group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'bootstrap-sass', '~> 2.3.2.0'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-ui-rails'
#end
gem 'hirb-unicode'
gem 'jquery-rails'
gem 'carrierwave'
# gem 'sidekiq'
#URL Command list
gem 'awesome_print', :require => 'ap'
gem 'quiet_assets', :group => :development
gem 'rails-erd', :group => :development
gem 'tinymce-rails'
gem 'haml'
#https://github.com/andi/simple-navigation/wiki/Installation
gem "simple-navigation"
#https://github.com/pdf/simple-navigation-bootstrap
gem 'simple-navigation-bootstrap'
#gem 'open-uri'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
gem 'pg'
gem 'taps'
gem 'devise'
#http://stackoverflow.com/questions/6379950/gmail-smtp-with-rails-3
#gem 'tlsmail'
gem 'cancan'
gem 'pry'
gem 'pry-remote'
gem 'pry-nav'
gem 'ipaddress'
# https://github.com/collectiveidea/delayed_job
# gem 'delayed_job_active_record'
# gem 'daemons'
gem "resque"
gem 'resque_mailer'
gem 'resque-scheduler'
gem 'rubyzip'
gem 'whenever', :require => false
Look at your Manifest file (app/assets/javascripts/application.js). Probably there you have something wrong. The order of files matters:
//= require jquery
//= require jquery_ujs
//= require bootstrap-select
//= require twitter/bootstrap
//= require turbolinks
//= require jquery.ui
....
Or check out your configs in config/environments/production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.cache_store = :dalli_store
#config.cache_store = :mem_cache_store
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true

config.consider_all_requests_local set to true without full trace

I'm working on a new app today this is my Gemfile :
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Static pages
gem 'high_voltage', '0.9.2'
# Dry Controller
gem 'coast'
# Light Views
gem 'slim'
gem 'formtastic'
# Uploading
gem 'paperclip'
# Authentication
gem 'devise'
gem 'cancan'
# Easing models
gem 'enumerize'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :test, :development do
gem 'sqlite3'
gem 'awesome_print'
# For slim genetaror instead default
gem 'slim-rails'
gem 'factory_girl_rails', '~> 4.0'
gem 'forgery'
end
gem 'jquery-rails'
And this an extract from my environment/development.rb :
config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.action_dispatch.best_standards_support = :builtin
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.assets.compress = false
config.assets.debug = true
Slim::Engine.set_default_options pretty: true, sort_attrs: false
When I go to a page with an error for example this one :
p
= #project.envelopedd
I get a 500 page error instead of the normal debug trace. Any idea to fix this ?
This is a "bug" in the Rails documentation. I got burned by this just now also. There is a PR open on the Rails repo to address the docs issue.
The TL;DR: is that you need to implement show_detailed_exceptions? instead of local_request?

Resources