Bootstrap 3 Glyphicons not showing on Heroku - ruby-on-rails-4

I've seen many questions and solutions for this issue on SO, but none have worked for me. The Glyphicons work great locally, but show as boxes on Heroku from desktop browsers.
I'm using them like this:
<span class="glyphicon glyphicon-trash"></span>
This is my gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.1.8'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails', '~> 3.1.0'
gem 'turbolinks'
gem 'jquery-turbolinks'
gem 'jbuilder', '~> 2.0.2'
gem 'bootstrap-sass', '~> 3.1.1.0'
gem 'twitter-bootstrap-rails', '~> 3.2.0'
gem 'devise', '~> 3.2.2'
gem 'simple_form'
gem "paperclip", "~> 4.2.0"
gem 'aws-sdk', '~> 1.32.0'
gem 'will_paginate', '3.0.7'
gem 'will_paginate-bootstrap'
gem "friendly_id", "~> 5.0.2"
gem 'faker', '1.2.0'
gem 'auto_html'
gem 'protected_attributes'
gem 'ckeditor', '~> 4.0.11'
gem 'font-awesome-rails'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development, :test do
gem 'sqlite3'
end
I currently have production.rb set like this after trying other fixes:
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
My application.rb file has the following:
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
# 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'
# Required for Devise on Heroku
config.assets.initialize_on_precompile = false
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.assets.precompile += Ckeditor.assets
config.assets.precompile += %w(ckeditor/*)
config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.precompile += [ 'styles.css.scss']
config.assets.precompile += [
'glyphicons-halflings.png',
'glyphicons-halflings-white.png'
]
I have also tried running
bundle exec rake assets:precompile
and
bundle exec rake assets:precompile RAILS_ENV=production
I have tried so many fixes, that something I have set now might be wrong. Everything works great locally. I also have an issue where a text-align: center is not being pushed to heroku from my CSS file. I'll post that as a separate issue, but I mention it in case it's a related issue with the asset pipeline.
This is how I load teh stylesheets in the app:
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
These are my stylesheets:
application.css.scss
pages.css.scss
posts.css.scss
scaffolds.css.scss
styles.css.scss
users.css.scss
in my application.css.scss:
*= require_self
*= require_tree .
*= require font-awesome
in my styles.css.scss
#import 'bootstrap';
#import url("//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css");
#import 'font-awesome';
#font-face {
font-family: 'Glyphicons Halflings';
src: font-path('glyphicons-halflings-regular.eot');
src: font-path('glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
font-path('glyphicons-halflings-regular.woff') format('woff'),
font-path('glyphicons-halflings-regular.ttf') format('truetype'),
font-path('glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
Here's the error from Chrome:
Font from origin 'http://thetens.herokuapp.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.thetens.us' is therefore not allowed access. The response had HTTP status code 404.
jquery-91eecca5c0fff73b540ae82e1b1833c8.js:3581 GET http://thetens.herokuapp.com/fonts/glyphicons-halflings-regular.woff jquery-91eecca5c0fff73b540ae82e1b1833c8.js:3581 (anonymous function)jquery-91eecca5c0fff73b540ae82e1b1833c8.js:3120 firejquery-91eecca5c0fff73b540ae82e1b1833c8.js:3232 self.fireWithjquery-91eecca5c0fff73b540ae82e1b1833c8.js:3444 jQuery.extend.readyjquery-91eecca5c0fff73b540ae82e1b1833c8.js:3475 completed
(index):1 Font from origin 'http://thetens.herokuapp.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.thetens.us' is therefore not allowed access. The response had HTTP status code 404.
(index):1 GET http://thetens.herokuapp.com/fonts/glyphicons-halflings-regular.ttf
Update: I commented out
# config.action_controller.asset_host = "http://thetens.herokuapp.com"
and now I only get two errors:
GET http://www.thetens.us/fonts/glyphicons-halflings-regular.woff jquery-6156cfcaa88efb694ac4fac3d8cef9c4.js:3581 (anonymous function)jquery-6156cfcaa88efb694ac4fac3d8cef9c4.js:3120 firejquery-6156cfcaa88efb694ac4fac3d8cef9c4.js:3232 self.fireWithjquery-6156cfcaa88efb694ac4fac3d8cef9c4.js:3444 jQuery.extend.readyjquery-6156cfcaa88efb694ac4fac3d8cef9c4.js:3475 completed
(index):1 GET http://www.thetens.us/fonts/glyphicons-halflings-regular.ttf

For me this worked out:
#import "bootstrap-sprockets";
#import "bootstrap";
I hope this helps you to! :)

You have to link absolutely to the font like
#import 'bootstrap';
#import url("//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css");
#import 'font-awesome';
#font-face {
font-family: 'Glyphicons Halflings';
src: font-path('/assets/fonts/glyphicons-halflings-regular.eot');
src: font-path('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
font-path('/assets/fonts/glyphicons-halflings-regular.woff') format('woff'),
font-path('/assets/fonts/glyphicons-halflings-regular.ttf') format('truetype'),
font-path('/assets/fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
Mark sure that the fonts are link properly in heroku

Had the same problem on heroku and this is caused by Cross-Origin Resource Sharing. That's why most config solutions don't work.
my solution was:
move all assets to S3 bucket (used asset_sync gem)
configureCORS on bucket (CORS) [IMPORTANT]

Related

Bundler:GemNotFound error even though gem is locally installed

In my application, I am using a cron job to execute a simple model method.
A few gems were required for this task.
I installed a gem by including it in the gemfile and running the command
bundle install
Now when I run the server, I get the following error:
/home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find mime-types-data-3.2016.0221 in any of the sources (Bundler::GemNotFound)
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/spec_set.rb:85:in `map!'
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/spec_set.rb:85:in `materialize'
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/definition.rb:140:in `specs'
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/definition.rb:185:in `specs_for'
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/definition.rb:174:in `requested_specs'
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/environment.rb:18:in `requested_specs'
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/runtime.rb:13:in `setup'
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler.rb:127:in `setup'
from /home/aditya9509/.rvm/gems/ruby-1.9.3-p551/gems/bundler-1.10.5/lib/bundler/setup.rb:18:in `<top (required)>'
from /home/aditya9509/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/aditya9509/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/aditya9509/Desktop/rubystack-2.0.0-33/projects/cricketStockExchange/config/boot.rb:3:in `<top (required)>'
from bin/rails:8:in `require_relative'
from bin/rails:8:in `<main>'
It says that the bundler was not able to locate mime-types-data-3.2016.0221 gem in any of the sources. To check, I ran the following command which gives a list of locally installed gems related to mime:
gem list | grep "mime"
This gave the following output:
mime-types (3.0, 2.99, 2.6.2)
mime-types-data (3.2016.0221)
Clearly the mime-types-data-3.2016.0221 is installed locally but bundler is not able to find it. Is there any fix to this. Below is my Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.3.18'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# 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'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'whenever', :require => false
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
gem 'mime-types-data','~> 3.2016.0221'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
I am not sure as to what more information would be appropriate so let me know, I will update my question as needed.
Thanks!
Does the issue persist when running the server with bundle exec rails s?

How to deploy Rails App using private_pub to heroku

I am trying to run my app on heroku which is using private_pub gem . Here in my local server I am running it perfectly . How can I push this app in heroku and run there perfectly . Here is my gem file :
source 'https://rubygems.org'
gem 'rails', '4.2.1'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'bcrypt', '3.1.7'
gem 'mailboxer'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sdoc', '0.4.0', group: :doc
gem 'devise'
gem 'paperclip', '~> 4.1'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'faker', '1.4.2'
gem 'chosen-rails'
gem 'jquery-turbolinks'
gem 'private_pub'
gem "thin"
#gem 'puma', '2.11.1'
group :development, :test do
#gem 'sqlite3', '1.3.9'
gem 'mysql2'
#gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
gem 'byebug', '3.4.0'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '2.11.1'
end
And This is my private_pub.yml file :
development:
server: "http://localhost:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
production:
server: "https://sheltered-sea-1191.herokuapp.com/faye"
secret_token: "mysecret key"
signature_expiration: 3600 # one hour
How can I push this app in heroku help me to push this on herok .
For this above question I have created a new heroku app and I put this code as it is told in this tutorial https://webprogramming29.wordpress.com/2013/02/15/setup-privatepub-or-faye-on-heroku/
And then I edited my code using the following tutorial and it is working great

Can't Precompile Assets Rails 4 bootstrap-sass DXImageTransform error [duplicate]

This question already has an answer here:
"non-terminal statement or declaration" error when using Microsoft's proprietary filter property in Sass
(1 answer)
Closed 7 years ago.
Im trying to precompile assets for production. Unless I include the bootstrap and font-awesome assets as static files (or host from CDN) sass-rails fails when trying to compile assets on production. My Gemfile looks like this:
# Default asset gems
gem 'coffee-rails', '~> 4.0.0'
gem 'sass-rails' , '~> 4.0.3'
gem 'uglifier' , '>= 1.3.0'
# Default gems
gem 'jbuilder', '~> 2.0'
gem 'sdoc' , '~> 0.4.0', group: :doc
# Added gems
gem 'carrierwave'
gem 'pg'
gem 'turbolinks'
gem 'restforce'
# Asset gems
gem 'jquery-rails'
gem 'autoprefixer-rails'
gem 'bootstrap-sass'
gem 'font-awesome-sass'
gem 'handlebars_assets'
gem 'iconv'
When i try to compile assets i get the following error:
➜ stylesheets git:(master) ✗ rake assets:precompile
(in /home/ubuntu/spice-conduit)
rake aborted!
Sass::SyntaxError: Invalid CSS after " filter: progid": expected ";", was ": DXImageTransf..."
(in /home/ubuntu/spice-conduit/app/assets/stylesheets/application.css)
(sass):3566
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:1147:in `expected'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:1085:in `expected'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:1080:in `tok!'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:586:in `block in declaration_or_ruleset'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:1123:in `call'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:1123:in `rethrow'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:592:in `declaration_or_ruleset'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:554:in `block_child'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:546:in `block_contents'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:535:in `block'
/home/ubuntu/.rvm/gems/ruby-2.1.3/gems/sass-3.2.19/lib/sass/scss/parser.rb:529:in `ruleset'
app.css file:
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require jquery-ui
*= require sweetalert
*= require vendors
*= require_tree .
*/
My scss file:
#import "font-awesome-sprockets";
#import "font-awesome";
#import "bootstrap-sprockets";
#import "bootstrap";
I've seen this issue reported here: https://github.com/rails/sass-rails/issues/37
but that issue is several years old.
Remove the white space between progid and DXImageTransform.Microsoft.gradient.
for ex.,
OLD SYNTAX
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#7adddd', endColorstr='#39cccc', GradientType=0) !important;
NEW SYNTAX
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#7adddd', endColorstr='#39cccc', GradientType=0) !important;
You can see in the NEW SYNTAX, I have removed extra space between progid and DXImageTransform.Microsoft.gradient().

Prawn in a Ruby on Rails app, failing on production

I am stuck on an issue with running prawn in production.
I have followed the Railscast (revised http://railscasts.com/episodes/153-pdfs-with-prawn-revised?view=asciicast) pretty much to the letter. It works great in my development environment (Mac OS X 10.9.1) but causes unicorn to falter on my server. My production server is (Redhat => Red Hat Enterprise Linux Server release 6.4 (Santiago)). I have the gem installed via Gemfile.
Gemfile:
gem 'prawn'
gem 'prawn-qrcode'
Controller: (show action)
def show
##classroom = Classroom.find(params[:id])
#classroom = find_classroom
#page_title = #classroom.location.name
#classroom_alt = #classroom.location.name + " - " + #classroom.room_number
#building = find_building(#classroom.location_id)
#owner = Owner.find(#classroom.owner_id)
#room_schedule_contact = RoomScheduleContact.find_by rmrecnbr:(#classroom.rmrecnbr)
#building_image = #building.picture.url(:medium).to_s
#building_sign_image = #building.building_sign.url(:thumb).to_s
#search = Classroom.search(params[:search])
##classroom_herprod = Building.find(params[:location_id]).building_short_code
respond_to do |format|
format.html # show.html.erb
format.png { render :qrcode => "http://rooms.lsa.umich.edu/classrooms/#{#classroom.facility_code_heprod}", :level => :l, :unit => 8 }
format.pdf do
pdf = ClassroomPdf.new(#classroom)
send_data pdf.render, type: "application/pdf",
disposition: "inline"
end
end
end
I have a pdfs directory with a classroom_pdf.rb file that includes the following.
class ClassroomPdf < Prawn::Document
def initialize(classroom)
super(top_margin: 70)
text "This is a pdf"
end
end
(This is stripped down from what I had, but it is the most basic version that works on my dev system and fails on production).
I am running the following
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
gem 'rails', '4.0.2'
The error in the unicorn.stderr.log is as follows.
E, [2014-02-07T12:39:20.400750 #7300] ERROR -- : reaped #<Process::Status: pid 7306 exit 1> worker=1
I, [2014-02-07T12:39:20.401257 #7300] INFO -- : worker=1 spawning...
I, [2014-02-07T12:39:20.463964 #7529] INFO -- : worker=1 spawned pid=7529
I, [2014-02-07T12:39:20.521524 #7529] INFO -- : Refreshing Gem list
E, [2014-02-07T12:39:29.938423 #7326] ERROR -- : uninitialized constant Prawn (NameError)
/var/www/rooms.lsa.umich.edu/html/iris/releases/20140207173433/app/pdfs/classroom_pdf.rb:1:in `<top (required)>'
/var/www/rooms.lsa.umich.edu/html/iris/shared/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
Here is the gemfile
source 'https://rubygems.org'
##gem 'rails', '3.2.14'
gem 'rails', '4.0.2'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
#gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
gem "haml"
#gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails'
gem 'bootstrap-sass', '~> 3.1.0'
#gem 'google-analytics-rails'
gem 'font-awesome-rails'
gem 'protected_attributes'
gem 'modernizr-rails'
gem "jquery-rails"
gem "devise", "3.0.3"
gem "cancan", ">= 1.6.9"
gem "rolify", ">= 3.2.0"
gem 'newrelic_rpm'
# QR-Code generation
gem 'rqrcode-rails3'
gem 'mini_magick'
gem 'prawn'
#gem 'prawn', '1.0.0.rc2'
gem 'prawn-qrcode'
#gem 'prawnto'
gem 'capistrano', '2.15.5'
#gem 'capistrano'
gem "simple_form"
gem 'will_paginate', '~> 3.0.5'
gem "therubyracer", :group => :assets, :platform => :ruby
gem 'will_paginate-bootstrap'
#gem 'kaminari'
## Used for uploading and resizing images (Need both paperclip and mini_magick)
gem "paperclip", "3.5.1"
#gem "meta_search"
gem "ransack"
gem 'annotate', ">=2.6.0"
group :production do
gem 'unicorn'
end
Any ideas?
It turns out that I needed to manually reboot unicorn for it to properly load the new gem file.

Rails 4 assets not loading in heroku after 'rake assets:precompile'

This is driving me insane! My app works properly on the local server, but when I uploaded to heroku, the css and js files didn't update. I read to precompile using rake assets:precompile to fix the issue, but then I uploaded to heroku again and now all my assets aren't loading at all! I've tried all variations of precompile, installed 12factor gem, turned some config settings from false to true, still not happening! When i look at the console, it says
[Error] ReferenceError: Can't find variable: jQuery
global code (application-38ccb09605964287831a37a0d9faf188.js, line 1)
but I do have Jquery! it works fine on local! I dunno what I'm doing wrong guys.
Gemfile
gem 'bootstrap-sass-rails'
gem 'rails_12factor', group: :production
gem 'rails', '4.0.0'
gem 'sqlite3', :group => [:development, :test]
group :production do
gem 'thin'
gem 'pg'
end
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
running $RAILS_ENV=production bundle exec rake assets:precompile made my heroku app work now. so i guess problem is fixed..
sorry, I don't have an explanation on why it works
Simply run
$ bundle exec rake assets:precompile
$ git add .
$ git commit -am "assets precompiled locally"
$ git push heroku master