2

I know this is a common issue and has been asked couple times here. I followed this method Bootstrap 3+Rails 4 - Certain Glyphicons not working it works in development and used to work in production but after working on my app in development and moving it to production it's stopped working anymore.I'm using Rails 4.2.5 on AWS ubuntu server. My assets were precompiled without errors.

Bootstrap files are placed in their appropriate directories in myapp/app/assets. My icons and background image are not working in production only.I checked my log file it shows these errors.

ActionController::RoutingError (No route matches [GET]     "/stylesheets/bootstrap.css"):

ActionController::RoutingError (No route matches [GET] "/javascripts/bootstrap.js"):

ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.woff2"):

etc

application.html.erb

    <%= stylesheet_link_tag    "bootstrap"  %>
    <%= javascript_include_tag "bootstrap" %>
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>

application.rb

 config.assets.paths << "#{Rails}/app/assets/fonts"
 config.assets.precompile += %w( .svg .eot .woff .ttf )

bootstrap.css

  @font-face {
    font-family: 'Glyphicons Halflings';
    src: url('/assets/glyphicons-halflings-regular.eot');
    src: url('/assets/glyphicons-halflings-regular.eot?#iefix')       
    format('embedded-opentype'), url('/assets/glyphicons-halflings-regular.woff')     
    format('woff'), url('/assets/glyphicons-halflings-regular.ttf')    
    format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons-    halflingsregular') format('svg');

application.css I renamed it to application.css.scss and still does not work. I'm not sure If I really need to rename it.

*= require_self
*= require bootstrap
*= require_tree .

application.js

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require jquery.raty
//= require ratyrate
//= require_tree .
Community
  • 1
  • 1
A1X
  • 1,099
  • 3
  • 8
  • 11
  • 1
    Try this one: `rake assets:precompile RAILS_ENV=production` – 7urkm3n Apr 08 '16 at 05:25
  • I did it precompiled them with no errors. I added my bootstrap.css you may check that out it could be my issue :) – A1X Apr 08 '16 at 05:26
  • did u try to use gem bootstrap ? – 7urkm3n Apr 08 '16 at 05:28
  • I used to have it but I deleted it it because the syntax, do I have to change my current syntax If I install it now ? – A1X Apr 08 '16 at 05:30
  • 1
    if u dnt use gem then `//= require_tree .` should cover for you there. you dont need to include in application.js and .css files. try to remove them then restart the server. – 7urkm3n Apr 08 '16 at 05:32
  • 1
    also, dont forget to remove from application.html.erb file too. – 7urkm3n Apr 08 '16 at 05:39
  • just installed the gem still does not work but it changed my view. I removed require_tree still the icons did not appear. – A1X Apr 08 '16 at 05:44
  • I still do not know why I'm getting errors in my log – A1X Apr 08 '16 at 05:45
  • Try this gem: https://github.com/twbs/bootstrap-sass , Remove everything from your `application.scss` and add this to it `@import "bootstrap-sprockets";` `@import "bootstrap";` – dp7 Apr 08 '16 at 05:50
  • Dnt remove require_tree . Remove bootstrap lines only //= bootstrap in js and css file also from applicationhtml erb file – 7urkm3n Apr 08 '16 at 05:51
  • 1
    @7urkm3n from the gem documentation **remove all the `*= require_self` and `*= require_tree.` statements from the `sass` file. Instead, use `@import` to import `Sass files`. Do not use `*= require` in Sass or your other stylesheets will not be able to access the Bootstrap mixins or variables.** – dp7 Apr 08 '16 at 05:54
  • I get this now even though files exist Sass::SyntaxError: File to import not found or unreadable: bootstrap-sprockets. Load paths: /home/ubuntu/senior-project/homeFoods/app/assets/fonts etc – A1X Apr 08 '16 at 06:08
  • @dkp He mentioned didnt use `gem bootstrap`, its just copied bootstrap files. – 7urkm3n Apr 08 '16 at 13:51
  • 1
    @7urkm3n yes, i was suggesting to use sass bootstrap. I find it a better way of using bootstrap in a rails app. :) – dp7 Apr 08 '16 at 15:41
  • Started GET "/homeFoods/fonts/glyphicons-halflings-regular.woff2" I see now this does not make sense why it's not getting the correct path ? – A1X Apr 08 '16 at 21:51

0 Answers0