2013-03-11 69 views
1

我一直在爲此奮鬥了幾天 - 我向我的rails應用程序添加了bootstrap(和其他一些寶石),但由於某種原因,相應的CSS文件沒有渲染因此引導程序樣式不顯示。Rails:資產在開發中沒有正確呈現

這裏是我的文件的相關部分:

application.html.erbapp/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.cssapp/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 . 
*/ 

(有此文件夾中也有很多更多的CSS文件包括bootstrap_and_overrides.cssgmaps4rails.css)。

並且服務器日誌的時候網頁加載完畢:

$ 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) 

這實際上得到在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> 

而且我Gemfile

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

gem 'gmaps4rails' 

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 

我將資產管道config/application.rb設置爲true,我沒有更改調試設置。我的RAILS_ENVdevelopment。據我瞭解,由於撥打require_tree .,導軌應該編譯並提供所有CSS文件,包括boostrap_and_overrides.css.scss。我多次運行rake assets:precompilebundle exec rake assets:precompile,但我認爲這不重要。我正在運行ruby 2.0.0p0(2013-02-24修訂版39474)。

真的很奇怪的是我和我的合作伙伴在這個項目上有完全相同的代碼(來自我們的github存儲庫),它在本地機器上工作,但它不適用於我的工作。有沒有人有任何意見,發生了什麼事?

+1

正確,您不需要在開發中預先編譯資源(實際上,您可能希望刪除/ public/assets中的所有文件)。你可以在Chrome瀏覽器的源代碼視圖中看到css的內容嗎?我在css鏈接出現之前遇到過類似的問題,但它們都是空的。 – kasperite 2013-03-11 22:40:43

+0

不,在Chrome中呈現的CSS文件是空的(這很奇怪,因爲它至少應包含'require'註釋等)。對於它的價值,'manifest.yml'中指定的'public/assets'中的MD5'd文件也是空的(但是在開發過程中這不應該出現問題,對不對?) 我意識到事情可能正在發生對於我的團隊中的其他人而不是我,因爲他們可能有'RAILS_ENV = production',但我也嘗試將我的設置設置爲生產,但沒有配置爲服務資產,所以我不認爲這是問題所在。 – 2013-03-11 23:21:36

+0

你可以在配置/環境中發佈你的development.rb(你說它與其他人沒有區別?)。我在生產中遇到了這個錯誤,但它是一個錯誤的獨角獸設置(不是rails問題)。這當然是你當地的問題。 – kasperite 2013-03-11 23:39:29

回答

1

我也在Rails 3.2.6中遇到同樣的問題,當我升級到Rails 3.2.15時它就消失了。