1

I've been struggling with this for a few days now - I added bootstrap (and some other gems) to my rails app, but for some reason the appropriate CSS files are not rendering and thus the bootstrap styles are not showing up.

Here are the relevant parts of my files:

application.html.erb in app/views/layouts:

<head>
  <title>Myapp</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <script type="text/javascript" src="https://raw.github.com/twitter/bootstrap/master/js/bootstrap-dropdown.js"></script>
</head>

application.css in app/assets/stylesheets:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * 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_self
 *= require_tree .
 */

(There are also plenty more CSS files in this folder, including bootstrap_and_overrides.css and gmaps4rails.css).

And the server log when I load the page:

$ rails server
=> Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
        SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
        This poses a security threat. It is strongly recommended that you
        provide a secret to prevent exploits that may be possible from crafted
        cookies. This will not be supported in future versions of Rack, and
        future versions will even invalidate your existing user cookies.

        Called from: /Users/me/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-3.2.8/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.
[2013-03-11 15:19:32] INFO  WEBrick 1.3.1
[2013-03-11 15:19:32] INFO  ruby 2.0.0 (2013-02-24) [x86_64-darwin11.4.2]
[2013-03-11 15:19:32] INFO  WEBrick::HTTPServer#start: pid=94815 port=3000


Started GET "/" for 127.0.0.1 at 2013-03-11 15:19:35 -0700
Processing by HomeController#index as HTML
  Rendered home/index.html.erb within layouts/application (2.8ms)
  Trip Load (0.2ms)  SELECT "trips".* FROM "trips" 
  Rendered layouts/_navigation.html.erb (62.0ms)
Completed 200 OK in 143ms (Views: 141.0ms | ActiveRecord: 1.3ms)

And the source code that actually gets rendered in Chrome:

<head>
  <title>Myapp</title>
  <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
  <script src="/assets/application.js?body=1" type="text/javascript"></script>
  <meta content="authenticity_token" name="csrf-param" />
<meta content="GfG+KCsrNZaChqWvUz/g5RqsdHrXOtumFzHaOjJmFQg=" name="csrf-token" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <script type="text/javascript" src="https://raw.github.com/twitter/bootstrap/master/js/bootstrap-dropdown.js"></script>
</head>

And my Gemfile:

gem "bootstrap-sass", '~> 2.3.0.1'
gem "simple_form"

gem 'gmaps4rails'

And config/environments/development.rb:

config.cache_classes = false

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.consider_all_requests_local       = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false

# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log

# 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

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5

# Do not compress assets
config.assets.compress = false

# Expands the lines which load the assets
config.assets.debug = true

I have the assets pipeline in config/application.rb set to true and I haven't changed the debug settings. My RAILS_ENV is development. As I understand, rails should be compiling and serving all of the CSS files including boostrap_and_overrides.css.scss because of the require_tree . call. I've run rake assets:precompile and bundle exec rake assets:precompile multiple times, but I don't think that should matter. Im running ruby 2.0.0p0 (2013-02-24 revision 39474).

The REALLY weird thing is that me and my partners on this project have the exact same code (from our github repository), and it works on their local machines but it doen't work on mine. Does anyone have any input at all into what's going on?

Noah Gilmore
  • 1,319
  • 2
  • 15
  • 24
  • 1
    correct, you don't need assets precompile in development(in fact, you might want to remove all files in /public/assets). Can you see the content of the css from source view in Chrome?I had similar problem before where the css links are there but they all empty. – kasperite Mar 11 '13 at 22:40
  • No, the CSS file that gets rendered in Chrome is empty (which is weird, since it should at least include the `require` comments etc). For what it's worth, the MD5'd file in `public/assets` specified in `manifest.yml` is also empty (but that shouldn't matter in development, right?) It occurred to me that things might be working for everyone else on my team but not for me because they might have `RAILS_ENV=production`, but I've tried setting mine to production as well, but nothing is configured to serve the assets, so I don't think that's the problem. – Noah Gilmore Mar 11 '13 at 23:21
  • can you post up your development.rb in config/environments(you said it's not different from others?). I got this error once in production but it was a wrong unicorn setup(not rails issues). It's your local issue for sure. – kasperite Mar 11 '13 at 23:39
  • you probably want to remove public/assets (or at least ALL of the files in that directory) in development mode, otherwise the rails server will serve those up instead of compiling the files on the fly. I would delete those files and restart the rails server – house9 Mar 11 '13 at 23:50
  • Sure, I just updated the post with it. I haven't changed that file, and at any rate it shouldn't matter, since everyone on my team has the same file (since we're pushing it to github), right? – Noah Gilmore Mar 11 '13 at 23:54
  • Also, removing everything from public/assets doesn't change anything, for some reason. – Noah Gilmore Mar 12 '13 at 00:12
  • just noticed something: `Rails 3.2.8 application starting in development` -> you NEED to upgrade rails to 3.2.12 ASAP - see http://weblog.rubyonrails.org/2013/1/8/Rails-3-2-11-3-1-10-3-0-19-and-2-3-15-have-been-released/ AND http://weblog.rubyonrails.org/2013/2/11/SEC-ANN-Rails-3-2-12-3-1-11-and-2-3-17-have-been-released/ – house9 Mar 12 '13 at 00:18
  • Well shit, I updated rails (to 3.2.12) in response to the above security issues and somehow everything works now. Anyone have any idea why? – Noah Gilmore Mar 12 '13 at 00:28

1 Answers1

1

I also encountered the same issue in Rails 3.2.6 which disappears when I upgrade to Rails 3.2.15.

Andy Liu
  • 41
  • 6