application.css不作为资产 [英] application.css not being served as an asset

查看:228
本文介绍了application.css不作为资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑4,5和6



8小时后,欢迎任何更多创意:)也许这个bug已经知道并解决了,但是当我们在app / assets / stylesheets中的.css.erb文件中有这样的情况时,我得到了编辑2& 3中描述的行为:

  li {
background-image:url(<%= asset_pathlogo_80px_80px.png%>);
}

问题部分似乎是 asset_path 方法调用,但是.css.scss也打断它:

  li {
background- image:url(image-path(logo_80px_80px.png));
}

我的GemFile是:

  source'http://rubygems.org'

gem'rails','3.1.3'
gem'pg' 0.11.0'
gem'gravatar_image_tag','1.0.0.pre2'
gem'will_paginate'
gem'rake'
gem'jquery-rails'
gem'nested_form'
gem'acts-as-taggable-on'

gem'sass-rails'
group:assets do
gem'coffee-rails' ,'〜> 3.1.0'
gem'uglifier','> = 1.0.3'
end

group:development do
gem'rspec-rails' 2.5.0'
gem'annotate','2.4.0'
gem'faker','0.3.1'
end


:test do
gem'rspec','2.5.0'
gem'webrat','0.7.1'
gem'factory_girl_rails','1.0'
end

group:production do
gem'therubyracer-heroku'
end


$ b b

My Gemfile.lock is:

  GEM 
remote:http://rubygems.org/
specs:
actionmailer(3.1.3)
actionpack(= 3.1.3)
mail(〜> 2.3.0)
actionpack b $ b activemodel(= 3.1.3)
activesupport(= 3.1.3)
builder(〜> 3.0.0)
erubis(〜> 2.7.0)$ b $ (〜> 0.6)
rack(〜> 1.3.5)
rack-cache(〜> 1.1)
rack-mount b $ b rack-test(〜> 0.6.1)
sprockets(〜> 2.0.3)
activemodel(3.1.3)
activesupport(= 3.1.3)
builder(〜> 3.0.0)
i18n(〜> 0.6)
activerecord(3.1.3)
activemodel(= 3.1.3)
activesupport(= 3.1.3)
arel(〜2.2.1)
tzinfo(〜> 0.3.29)
activeresource(3.1.3)
activemodel(= 3.1.3)
activesupport = 3.1.3)
activesupport(3.1.3)
multi_json(〜> 1.0)
act-as-taggable-on(2.2.1)
rails ; 3.1)
annotate(2.4.0)
arel(2.2.1)
builder(3.0.0)
coffee-rails -script(> = 2.2.0)
railties(〜> 3.1.0)
coffee-script(2.2.0)
coffee-script-source
execjs
coffee-script-source(1.1.3)
diff-lcs(1.1.3)
erubis(2.7.0)
execjs(1.2.12)
multi_json (〜> 1.0)
factory_girl(1.3.3)
factory_girl_rails(1.0)
factory_girl(〜> 1.3)
rails(> = 3.0.0.beta4)
faker(0.3.1)
gravatar_image_tag(1.0.0.pre2)
hike(1.2.1)
i18n(0.6.0)
jquery-rails 1.0.19)
railties(〜> 3.0)
thor(〜> 0.14)
json(1.6.3)
mail(2.3.0)
i18n(> = 0.4.0)
mime类型(〜> 1.16)
treetop(〜> 1.4.8)
mime-types(1.17.2)
multi_json(1.0.4)
nested_form 0.1.1)
nokogiri(1.5.0-x86-mingw32)
pg(0.11.0-x86-mingw32)
polyglot(0.3.3)
rack 5)
rack-cache(1.1)
rack(> = 0.4)
rack-mount(0.8.3)
rack(> = 1.0.0)
rack-ssl(1.3.2)
rack
rack-test(0.6.1)
rack(> = 1.0)
rails $ b actionmailer(= 3.1.3)
actionpack(= 3.1.3)
activerecord(= 3.1.3)
activeresource(= 3.1.3)
activesupport .3)
bundler(〜> 1.0)
railties(= 3.1.3)
railties(3.1.3)
actionpack(= 3.1.3)
activesupport(= 3.1.3)
rack-ssl(〜> 1.3.2)
rake(> = 0.8.7)
rdoc(〜 3.4)
thor(〜> 0.14.6)
rake(0.9.2.2)
rdoc(3.12)
json(〜> 1.4)
rspec 2.5.0)
rspec-core(〜> 2.5.0)
rspec-expectations(〜> 2.5.0)
rspec-mocks b $ b rspec-core(2.5.2)
rspec-expectations(2.5.0)
diff-lcs(〜> 1.1.2)
rspec-mocks
rspec-rails(2.5.0)
actionpack(〜> 3.0)
activesupport(〜> 3.0)
railties(〜> 3.0)
rspec (〜> 2.5.0)
sass(3.1.12)
sass-rails(3.1.5)
actionpack(〜> 3.1.0)
railties > 3.1.0)
sass(〜> 3.1.10)
tilt(〜> 1.3.2)
sprockets(2.0.3)
hike ; 1.2)
rack(〜> 1.0)
tilt(〜> 1.1,!= 1.3.0)
therubyracer-heroku(0.8.1.pre3)
thor (0.14.6)
tilt(1.3.3)
treetop(1.4.10)
polyglot
polyglot(> = 0.3.1)
tzinfo .31)
uglifier(1.2.0)
execjs(> = 0.3.0)
multi_json(> = 1.0.2)
webrat b $ b nokogiri(> = 1.2.0)
rack(> = 1.0)
rack-test(> = 0.5.3)
will_paginate
$ b PLATFORMS
x86-mingw32

DEPENDENCIES
act-as-taggable-on
annotate(= 2.4.0)
coffee -rails(〜 3.1.0)
factory_girl_rails(= 1.0)
faker(= 0.3.1)
gravatar_image_tag(= 1.0.0.pre2)
jquery-rails
nested_form
pg(= 0.11.0)
rails(= 3.1.3)
rake
rspec(= 2.5.0)
rspec-rails
sass-rails
therubyracer-heroku
uglifier(> = 1.0.3)
webrat(= 0.7.1)
will_paginate

application.rb内容:

  require File.expand_path('../ boot',__FILE__)

需要'rails / all'


如果定义? b Bundler.require(* Rails.groups(:assets =>%w(开发测试)))
end

模块AjpApp
类Application< Rails :: Application
config.encoding =utf-8
config.filter_parameters + = [:password]
config.assets.enabled = true
config.assets.version ='1.0'
end
end

config / environments / production.rb内容:

  AjpApp :: Application.configure do 
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true
config.assets .digest = true
config.i18n.fallbacks = true
config.active_support.deprecation =:notify
end

---归档---



ORIGINAL POST / p>

我有一个Rails 3.1应用程序,在生产模式下提供application.css文件。 遇到一些无关的问题后,我发现了使用以下方法重新编译资源

  bundle exec rake assets:precompile RAILS_ENV = production 

我的application.css文件,预编译产生:'application-79d6fafe46c10758d8f5a921f1e55ecd.css',但是现在不被服务,尽管存在于public / assets文件夹中。 application.js文件服务得很好(如application-9a36deba94d6308ab9bebe4e30a93959.js)。另外我注意到,这个问题首次出现后,我创建了一个.css.erb文件,建议的文章预编译



对我试图做的任何想法?我将尝试撤消.css.erb文件,再次运行预编译并查看是否获得了我的application.css文件。



编辑1



问题不是将 .css 文件更改为 .css。 erb 。和erb工作正常。当使用 asset_path 函数时,问题似乎来了:例如:

 。 button_one {
background-image:url(<%= asset_pathactivities / text_editor_toolbar.png%>);
}

这样可以提供正确的字符串,例如: assets /activities/text_editor_toolbar.png,它显示在编译的 application-(hash).css 文件中,这是奇怪的::|:@



编辑2
好​​吧,这只是更好,但weirder。我在生产模式下运行一次,运行失败,在开发中再次运行,然后再次在生产环境中运行。它将花费年龄并启动Microsoft控制台脚本主机,就像它预编译资产,从输出看来,它似乎正在做,在最终呈现页面和服务应用程序之前 - (哈希).css successfully:

  C:\documents\ror\ajp_app> rails s -e production 
=>启动WEBrick
=> Rails 3.1.3应用程序在生产中开始于http://0.0.0.0:3000
=>调用-d来分离
=> Ctrl-C关闭服务器
[2011-12-19 23:59:12] INFO WEBrick 1.3.1
[2011-12-19 23:59:12] INFO ruby​​ 1.9.2(2011 -07-09)[i386-mingw32]
[2011-12-19 23:59:12]信息WEBrick :: HTTPServer#start:pid = 4052 port = 3000
cache:[GET /] miss


在2011-12-19开始获取127.0.0.1的GET/+0000
由PagesController处理#home为HTML
渲染的页面/布局/应用程序中的home.html.erb(85.0ms)
渲染的布局/ _header.html.erb(2.0ms)
渲染的布局/ _footer.html.erb(1.0ms)
完成200 OK在393ms(视图:382.0ms | ActiveRecord:10.0ms)
缓存:[GET /assets/application-a05ca896e645eacb50266c7866d18a0f.css] miss


开始GET /assets/application-a05ca896e645eacb50266c7866d18a0f.cssfor 127.0.0.1 at 2011-12-19 23:59:27 +0000
不存在的资产应用程序-a05ca896e645eacb50266c7866d18a0f.css @ a05ca896e645eacb50266c7866d18a0f
服务资产/应用程序-a05ca896e645eacb50266c7866d18a0f .css - 404 Not Found(44ms)

ActionController :: RoutingError(No route matches [GET]/assets/application-a05ca896e645eacb50266c7866d18a0f.css):


Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues / layout
(1.0ms )
[2011-12-19 23:59:39] INFO要关闭...
[2011-12-19 23:59:39] INFO WEBrick :: HTTPServer#start done。
退出

C:\documents\ajp_app> rails s
=>启动WEBrick
=> Rails 3.1.3应用程序开始开发在http://0.0.0.0:3000
=>调用-d来分离
=> Ctrl-C关闭服务器
[2011-12-20 00:00:14] INFO WEBrick 1.3.1
[2011-12-20 00:00:14] INFO ruby​​ 1.9.2(2011 -07-09)[i386-mingw32]
[2011-12-20 00:00:14] INFO WEBrick :: HTTPServer#start:pid = 2752 port = 3000


启动GET/127.0.0.1在2011-12-20 00:00:20 +0000
处理PagesController#home为HTML
←[1m←[36m(0.0ms)← [0m←[1mSHOW search_path←[0m
←[1m←[35mUser Load(1.0ms)←[0m SELECTusers。* FROMusersWHEREusers。id= 1 LIMIT 1
渲染的页面/ home.html.erb在布局/应用程序(171.0ms)
编译的application.css(4ms)(pid 2752)
编译colours.css(9ms)(pid 2752)
编译custom.css(1ms)(pid 2752)
编译activity.css(26ms)(pid 2752)
编译jquery / jquery-ui-1.8.13.custom.css (pid 2752)
编译的ellib / elcommon.css(30ms)(pid 2752)
编译的ellib / eldialogform.css(0ms)(pid 2752)
编译elrte / elrte.css )(bid 2752)
编译活动/ text_editor.css(2ms)(pid 2752)
编译错误.activities.css(0ms)(pid 2752)
编译错误_and_notices.css (pid 2752)
编译的general.css(0ms)(pid 2752)
编译的application.js(15ms)(pid 2752)
编译jquery.js(13ms)(pid 2752)
编译jquery_ujs.js(0ms)(pid 2752)
编译jquery-ui.js(19ms)(pid 2752)
编译AJP_main.js(1ms)(pid 2752)
编译ajp.utilities.js(2ms)(pid 2752)
渲染布局/ _header.html.erb(4.0ms)
渲染布局/ _footer.html.erb(2.0ms)
完成200 OK in 1091ms(Views:1076.0ms | ActiveRecord:15.0ms)


启动GET/assets/custom.css?body=1for 127.0.0.1 at 2011-12-20 00:00:28 +0000
服务资源/custom.css - 304未修改(6ms)


启动GET/assets/jquery/jquery-ui-1.8.13.custom.css?body=1 for 127.0.0.1 at 2011-12-20 00:00:28 +0000
服务器资源/jquery/jquery-ui-1.8.13.custom.css - 304未修改(7ms)


启动GET/assets/ellib/eldialogform.css?body=1for 127.0.0.1 at 2011-12-20 00:00:28 +0000
服务资产/ ellib / eldialogform .css - 304未修改(5ms)


启动GET/assets/elrte/elrte.css?body=1for 127.0.0.1 at 2011-12-20 00:00 :28 +0000
服务资产/elrte/elrte.css - 304未修改(5ms)


开始GET/assets/activities/text_editor.css?body=1 for 127.0.0.1 at 2011-12-20 00:00:28 +0000
服务器资源/activities/text_editor.css - 304未修改(9ms)


开始GET/assets/activity.css?body=1for 127.0.0.1 at 2011-12-20 00:00:28 +0000
服务器资源/activity.css - 200 OK(10ms)


启动GET/assets/errors.activities.css?body=1for 127.0.0.1 at 2011-12-20 00:00:28 +0000
服务的资源/错误。 activities.css - 304未修改(3ms)


启动GET/assets/errors_and_notices.css?body=1for 127.0.0.1 at 2011-12-20 00:00: 28 +0000
服务资源/errors_and_notices.css - 304未修改(3ms)


启动GET/assets/general.css?body=1for 127.0.0.1 at 2011-12-20 00:00:28 +0000
服务资源/general.css - 304未修改(3ms)


启动GET/ assets / jquery。 js?body = 1for 127.0.0.1 at 2011-12-20 00:00:28 +0000
服务器资源/jquery.js - 304未修改(12ms)


开始GET/assets/jquery_ujs.js?body=1为127.0.0.1在2011-12-20 00:00:28 +0000
服务器资源/jquery_ujs.js - 304未修改(8ms)


开始GET/assets/jquery-ui.js?body=1for 127.0.0.1 at 2011-12-20 00:00:29 +0000
投放asset /jquery-ui.js - 304未修改(42ms)


在2011-12-20开始获取/assets/AJP_main.js?body=1为127.0.0.1 00:00:29 +0000
服务资产/AJP_main.js - 304未修改(3ms)


开始GET/assets/ajp.utilities.js?body= 1for 127.0.0.1 at 2011-12-20 00:00:29 +0000
服务资产/ajp.utilities.js - 304未修改(10ms)


启动GET/assets/ellib/elcommon.css?body=1for 127.0.0.1 at 2011-12-20 00:00:29 +0000
服务器资源/ellib/elcommon.css - 304未修改5ms)


开始GET/assets/colours.css?body=1for 127.0.0.1 at 2011-12-20 00:00:29 +0000
服务资产/colours.css - 304未修改(12ms)


开始在2011-12-20为GET //assets/activities/hello.png127.0.0.1 00:00: 30 +0000
伺服器资产/activities/hello.png - 404未找到(13毫秒)

ActionController :: RoutingError(没有路线匹配[GET]/assets/activities/hello.png ):


渲染C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error .erb within rescues / layout
(1.0ms)
[2011-12-20 00:00:37] INFO要关机...
[2011-12-20 00:00 :37] INFO WEBrick :: HTTPServer#start done。
退出

C:\documents\ajp_app> rails s -e production
=>启动WEBrick
=> Rails 3.1.3应用程序在生产中开始于http://0.0.0.0:3000
=>调用-d来分离
=> Ctrl-C关闭服务器
[2011-12-20 00:01:17] INFO WEBrick 1.3.1
[2011-12-20 00:01:17] INFO ruby​​ 1.9.2(2011 -07-09)[i386-mingw32]
[2011-12-20 00:01:17] INFO WEBrick :: HTTPServer#start:pid = 5912 port = 3000
cache:[GET /] miss


在2011-12-20开始为127.0.0.1 GET/+0000
由PagesController处理#home为HTML
渲染的页面/布局/应用程序中的home.html.erb(91.0ms)
渲染布局/ _header.html.erb(3.0ms)
渲染布局/ _footer.html.erb(1.0ms)
完成200 OK在400ms(视图:387.0ms | ActiveRecord:12.0ms)
缓存:[GET /assets/application-a05ca896e645eacb50266c7866d18a0f.css]小姐,存储


启动GET/assets/application-a05ca896e645eacb50266c7866d18a0f.css为127.0.0.1在2011-12-20 00:01:21 +0000
编译的应用程序a05ca896e645eacb50266c7866d18a0f.css(pid 5912)
编译colours.css(9ms)(pid 5912)
编译custom.css(0ms)(pid 5912)
编译activity.css(21ms)(pid 5912)
编译jquery / jquery- ui-1.8.13.custom.css(1ms)(pid 5912)
编译的ellib / elcommon.css(0ms)(pid 5912)
编译的ellib / eldialogform.css(1ms)(pid 5912)
编译elrte / elrte.css(1ms)(pid 5912)
编译活动/ text_editor.css(0ms)(pid 5912)
编译错误.activities.css(1ms)(pid 5912) )
编译的errors_and_notices.css(0ms)(pid 5912)
编译的general.css(0ms)(pid 5912)
服务器资源/application-a05ca896e645eacb50266c7866d18a0f.css - 200 OK(871ms)
cache:[GET /assets/application-9a36deba94d6308ab9bebe4e30a93959.js] miss


启动GET/assets/application-9a36deba94d6308ab9bebe4e30a93959.jsfor 127.0.0.1 at 2011-12- 20 00:01:22 +0000
编译的应用程序 - 9a36deba94d6308ab9bebe4e30a93959.js(9ms)(pid 5912)
编译的jquery.js(13ms)(pid 5912)
编译jquery_ujs.js )(bid 5912)
编译的jquery-ui.js(19ms)(pid 5912)
编译的AJP_main.js(0ms)(pid 5912)
编译ajp.utilities.js(32ms) (pid 5912)
服务资产/application-9a36deba94d6308ab9bebe4e30a93959.js - 304未修改(110802ms)
缓存:[GET /assets/logo_80px_80px-27d7b084daa398621574b10963529e84.png] miss


启动GET/assets/logo_80px_80px-27d7b084daa398621574b10963529e84.pngfor 127.0.0.1 at 2011-12-20 00:03:13 +0000
服务器资源/logo_80px_80px-27d7b084daa398621574b10963529e84.png - 304未修改(3ms )
cache:[GET /assets/hello.png] miss


启动GET/assets/hello.pngfor 127.0.0.1 at 2011-12-20 00 :03:13 +0000
服务资源/hello.png - 404未找到(3ms)

ActionController :: RoutingError(没有路由匹配[GET]/assets/hello.png ):


渲染C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error。 erb within rescues / layout
(1.0ms)




:-D
&
:-o



编辑3
您不需要运行一次生产模式首先(即它实际上是在开发中运行的行为,这样做会触发生产模式以重新预编译资产)。使用 rake 预先编译资源后,只需要以开发模式运行,请求页面( 是必需的),然后运行



现在,我们的机器已经完全重新启动了(win 7-64bit) 。所以我认为这是一个一致的错误。



StackOverflow是继续讨论的最佳位置,或者最好继续使用

我曾经使用过github.com/sstephenson/sprockets-完全相同的问题,并通过在我的production.rb文件中将此选项更改为true(在默认情况下为false)解决它。

 #禁用Rails的静态资产服务器(Apache或nginx已经这样做)
config.serve_static_assets = true

从我的理解,设置这个选项为false是有意义的,如果你是在Apache或nginx下运行,这不是我的情况。


EDIT 4, 5 and 6

8 hours in, any more ideas are welcome :) Maybe this bug is already known and solved, but I get the behaviour I described in edit 2&3, when you have this in a .css.erb file in app/assets/stylesheets :

li {
    background-image: url(<%= asset_path "logo_80px_80px.png" %>);
}

The problem part seems to be the asset_path method call, but .css.scss also breaks it with:

li {
    background-image: url(image-path("logo_80px_80px.png"));
}

My GemFile is:

source 'http://rubygems.org'

gem 'rails', '3.1.3'
gem 'pg', '0.11.0'
gem 'gravatar_image_tag', '1.0.0.pre2'
gem 'will_paginate'
gem 'rake'
gem 'jquery-rails'
gem 'nested_form'
gem 'acts-as-taggable-on'

gem 'sass-rails'
group :assets do
  gem 'coffee-rails', '~> 3.1.0'
  gem 'uglifier', '>= 1.0.3'
end

group :development do
  gem 'rspec-rails', '2.5.0'
  gem 'annotate', '2.4.0'
  gem 'faker', '0.3.1'
end


group :test do
  gem 'rspec', '2.5.0'
  gem 'webrat', '0.7.1'
  gem 'factory_girl_rails', '1.0'
end

group :production do
  gem 'therubyracer-heroku'
end

My Gemfile.lock is:

GEM
  remote: http://rubygems.org/
  specs:
    actionmailer (3.1.3)
      actionpack (= 3.1.3)
      mail (~> 2.3.0)
    actionpack (3.1.3)
      activemodel (= 3.1.3)
      activesupport (= 3.1.3)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      i18n (~> 0.6)
      rack (~> 1.3.5)
      rack-cache (~> 1.1)
      rack-mount (~> 0.8.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.0.3)
    activemodel (3.1.3)
      activesupport (= 3.1.3)
      builder (~> 3.0.0)
      i18n (~> 0.6)
    activerecord (3.1.3)
      activemodel (= 3.1.3)
      activesupport (= 3.1.3)
      arel (~> 2.2.1)
      tzinfo (~> 0.3.29)
    activeresource (3.1.3)
      activemodel (= 3.1.3)
      activesupport (= 3.1.3)
    activesupport (3.1.3)
      multi_json (~> 1.0)
    acts-as-taggable-on (2.2.1)
      rails (~> 3.1)
    annotate (2.4.0)
    arel (2.2.1)
    builder (3.0.0)
    coffee-rails (3.1.1)
      coffee-script (>= 2.2.0)
      railties (~> 3.1.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.1.3)
    diff-lcs (1.1.3)
    erubis (2.7.0)
    execjs (1.2.12)
      multi_json (~> 1.0)
    factory_girl (1.3.3)
    factory_girl_rails (1.0)
      factory_girl (~> 1.3)
      rails (>= 3.0.0.beta4)
    faker (0.3.1)
    gravatar_image_tag (1.0.0.pre2)
    hike (1.2.1)
    i18n (0.6.0)
    jquery-rails (1.0.19)
      railties (~> 3.0)
      thor (~> 0.14)
    json (1.6.3)
    mail (2.3.0)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.17.2)
    multi_json (1.0.4)
    nested_form (0.1.1)
    nokogiri (1.5.0-x86-mingw32)
    pg (0.11.0-x86-mingw32)
    polyglot (0.3.3)
    rack (1.3.5)
    rack-cache (1.1)
      rack (>= 0.4)
    rack-mount (0.8.3)
      rack (>= 1.0.0)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.1)
      rack (>= 1.0)
    rails (3.1.3)
      actionmailer (= 3.1.3)
      actionpack (= 3.1.3)
      activerecord (= 3.1.3)
      activeresource (= 3.1.3)
      activesupport (= 3.1.3)
      bundler (~> 1.0)
      railties (= 3.1.3)
    railties (3.1.3)
      actionpack (= 3.1.3)
      activesupport (= 3.1.3)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (~> 0.14.6)
    rake (0.9.2.2)
    rdoc (3.12)
      json (~> 1.4)
    rspec (2.5.0)
      rspec-core (~> 2.5.0)
      rspec-expectations (~> 2.5.0)
      rspec-mocks (~> 2.5.0)
    rspec-core (2.5.2)
    rspec-expectations (2.5.0)
      diff-lcs (~> 1.1.2)
    rspec-mocks (2.5.0)
    rspec-rails (2.5.0)
      actionpack (~> 3.0)
      activesupport (~> 3.0)
      railties (~> 3.0)
      rspec (~> 2.5.0)
    sass (3.1.12)
    sass-rails (3.1.5)
      actionpack (~> 3.1.0)
      railties (~> 3.1.0)
      sass (~> 3.1.10)
      tilt (~> 1.3.2)
    sprockets (2.0.3)
      hike (~> 1.2)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    therubyracer-heroku (0.8.1.pre3)
    thor (0.14.6)
    tilt (1.3.3)
    treetop (1.4.10)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.31)
    uglifier (1.2.0)
      execjs (>= 0.3.0)
      multi_json (>= 1.0.2)
    webrat (0.7.1)
      nokogiri (>= 1.2.0)
      rack (>= 1.0)
      rack-test (>= 0.5.3)
    will_paginate (3.0.2)

PLATFORMS
  x86-mingw32

DEPENDENCIES
  acts-as-taggable-on
  annotate (= 2.4.0)
  coffee-rails (~> 3.1.0)
  factory_girl_rails (= 1.0)
  faker (= 0.3.1)
  gravatar_image_tag (= 1.0.0.pre2)
  jquery-rails
  nested_form
  pg (= 0.11.0)
  rails (= 3.1.3)
  rake
  rspec (= 2.5.0)
  rspec-rails (= 2.5.0)
  sass-rails
  therubyracer-heroku
  uglifier (>= 1.0.3)
  webrat (= 0.7.1)
  will_paginate

application.rb contents:

require File.expand_path('../boot', __FILE__)

require 'rails/all'


if defined?(Bundler)
  Bundler.require(*Rails.groups(:assets => %w(development test)))
end

module AjpApp
  class Application < Rails::Application
    config.encoding = "utf-8"
    config.filter_parameters += [:password]
    config.assets.enabled = true
    config.assets.version = '1.0'
  end
end

config/environments/production.rb contents:

AjpApp::Application.configure do
  config.cache_classes = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = false
  config.assets.compress = true
  config.assets.compile = true
  config.assets.digest = true
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
end

---Archived---

ORIGINAL POST

I have a Rails 3.1 application that was serving the application.css file when in production mode. After having some unrelated problems I found out about precompiling the assets using:

bundle exec rake assets:precompile RAILS_ENV=production

My application.css file, pre-compiled to produce: 'application-79d6fafe46c10758d8f5a921f1e55ecd.css' but is now not being served despite being present in the public/assets folder. The application.js file is being served fine (as application-9a36deba94d6308ab9bebe4e30a93959.js). Also I note that this problem first appeared after I created a .css.erb file, as suggested by the article on precompilation.

Any thoughts on what I try to do? I'm going to try undoing the .css.erb file, run precompilation again and see if I get my application.css file served.

EDIT 1

Problem does not come from changing .css file to .css.erb. And the erb works fine. Problem seems to come when the asset_path function is used e.g.:

.button_one {
    background-image: url(<%= asset_path "activities/text_editor_toolbar.png" %>);
}

This works to give the correct string e.g.: assets/activities/text_editor_toolbar.png", which shows up in the compiled application-(hash).css file which is served in development but not production mode. This is so weird. :| :@

Edit 2 Okay this just got better, but weirder. Seems if I run it once in production mode, it fails. Run it again in development, then again in production and it'll spend ages and launch the 'Microsoft Console Based Script Host' just like it's precompiling the assets, which from the output it seems like it's doing, before finally rendering the page and serving the application-(hash).css successfully:

C:\documents\ror\ajp_app>rails s -e production
=> Booting WEBrick
=> Rails 3.1.3 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-19 23:59:12] INFO  WEBrick 1.3.1
[2011-12-19 23:59:12] INFO  ruby 1.9.2 (2011-07-09) [i386-mingw32]
[2011-12-19 23:59:12] INFO  WEBrick::HTTPServer#start: pid=4052 port=3000
cache: [GET /] miss


Started GET "/" for 127.0.0.1 at 2011-12-19 23:59:26 +0000
  Processing by PagesController#home as HTML
Rendered pages/home.html.erb within layouts/application (85.0ms)
Rendered layouts/_header.html.erb (2.0ms)
Rendered layouts/_footer.html.erb (1.0ms)
Completed 200 OK in 393ms (Views: 382.0ms | ActiveRecord: 10.0ms)
cache: [GET /assets/application-a05ca896e645eacb50266c7866d18a0f.css] miss


Started GET "/assets/application-a05ca896e645eacb50266c7866d18a0f.css" for 127.0.0.1 at 2011-12-19 23:59:27 +0000
Nonexistent asset application-a05ca896e645eacb50266c7866d18a0f.css @ a05ca896e645eacb50266c7866d18a0f
Served asset /application-a05ca896e645eacb50266c7866d18a0f.css - 404 Not Found (44ms)

ActionController::RoutingError (No route matches [GET] "/assets/application-a05ca896e645eacb50266c7866d18a0f.css"):


Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout
 (1.0ms)
[2011-12-19 23:59:39] INFO  going to shutdown ...
[2011-12-19 23:59:39] INFO  WEBrick::HTTPServer#start done.
Exiting

C:\documents\ajp_app>rails s
=> Booting WEBrick
=> Rails 3.1.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-20 00:00:14] INFO  WEBrick 1.3.1
[2011-12-20 00:00:14] INFO  ruby 1.9.2 (2011-07-09) [i386-mingw32]
[2011-12-20 00:00:14] INFO  WEBrick::HTTPServer#start: pid=2752 port=3000


Started GET "/" for 127.0.0.1 at 2011-12-20 00:00:20 +0000
  Processing by PagesController#home as HTML
  ←[1m←[36m (0.0ms)←[0m  ←[1mSHOW search_path←[0m
  ←[1m←[35mUser Load (1.0ms)←[0m  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Rendered pages/home.html.erb within layouts/application (171.0ms)
Compiled application.css  (4ms)  (pid 2752)
Compiled colours.css  (9ms)  (pid 2752)
Compiled custom.css  (1ms)  (pid 2752)
Compiled activity.css  (26ms)  (pid 2752)
Compiled jquery/jquery-ui-1.8.13.custom.css  (1ms)  (pid 2752)
Compiled ellib/elcommon.css  (30ms)  (pid 2752)
Compiled ellib/eldialogform.css  (0ms)  (pid 2752)
Compiled elrte/elrte.css  (0ms)  (pid 2752)
Compiled activities/text_editor.css  (2ms)  (pid 2752)
Compiled errors.activities.css  (0ms)  (pid 2752)
Compiled errors_and_notices.css  (0ms)  (pid 2752)
Compiled general.css  (0ms)  (pid 2752)
Compiled application.js  (15ms)  (pid 2752)
Compiled jquery.js  (13ms)  (pid 2752)
Compiled jquery_ujs.js  (0ms)  (pid 2752)
Compiled jquery-ui.js  (19ms)  (pid 2752)
Compiled AJP_main.js  (1ms)  (pid 2752)
Compiled ajp.utilities.js  (2ms)  (pid 2752)
Rendered layouts/_header.html.erb (4.0ms)
Rendered layouts/_footer.html.erb (2.0ms)
Completed 200 OK in 1091ms (Views: 1076.0ms | ActiveRecord: 15.0ms)


Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /custom.css - 304 Not Modified (6ms)


Started GET "/assets/jquery/jquery-ui-1.8.13.custom.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /jquery/jquery-ui-1.8.13.custom.css - 304 Not Modified (7ms)


Started GET "/assets/ellib/eldialogform.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /ellib/eldialogform.css - 304 Not Modified (5ms)


Started GET "/assets/elrte/elrte.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /elrte/elrte.css - 304 Not Modified (5ms)


Started GET "/assets/activities/text_editor.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /activities/text_editor.css - 304 Not Modified (9ms)


Started GET "/assets/activity.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /activity.css - 200 OK (10ms)


Started GET "/assets/errors.activities.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /errors.activities.css - 304 Not Modified (3ms)


Started GET "/assets/errors_and_notices.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /errors_and_notices.css - 304 Not Modified (3ms)


Started GET "/assets/general.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /general.css - 304 Not Modified (3ms)


Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /jquery.js - 304 Not Modified (12ms)


Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2011-12-20 00:00:28 +0000
Served asset /jquery_ujs.js - 304 Not Modified (8ms)


Started GET "/assets/jquery-ui.js?body=1" for 127.0.0.1 at 2011-12-20 00:00:29 +0000
Served asset /jquery-ui.js - 304 Not Modified (42ms)


Started GET "/assets/AJP_main.js?body=1" for 127.0.0.1 at 2011-12-20 00:00:29 +0000
Served asset /AJP_main.js - 304 Not Modified (3ms)


Started GET "/assets/ajp.utilities.js?body=1" for 127.0.0.1 at 2011-12-20 00:00:29 +0000
Served asset /ajp.utilities.js - 304 Not Modified (10ms)


Started GET "/assets/ellib/elcommon.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:29 +0000
Served asset /ellib/elcommon.css - 304 Not Modified (5ms)


Started GET "/assets/colours.css?body=1" for 127.0.0.1 at 2011-12-20 00:00:29 +0000
Served asset /colours.css - 304 Not Modified (12ms)


Started GET "/assets/activities/hello.png" for 127.0.0.1 at 2011-12-20 00:00:30 +0000
Served asset /activities/hello.png - 404 Not Found (13ms)

ActionController::RoutingError (No route matches [GET] "/assets/activities/hello.png"):


Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout
 (1.0ms)
[2011-12-20 00:00:37] INFO  going to shutdown ...
[2011-12-20 00:00:37] INFO  WEBrick::HTTPServer#start done.
Exiting

C:\documents\ajp_app>rails s -e production
=> Booting WEBrick
=> Rails 3.1.3 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-20 00:01:17] INFO  WEBrick 1.3.1
[2011-12-20 00:01:17] INFO  ruby 1.9.2 (2011-07-09) [i386-mingw32]
[2011-12-20 00:01:17] INFO  WEBrick::HTTPServer#start: pid=5912 port=3000
cache: [GET /] miss


Started GET "/" for 127.0.0.1 at 2011-12-20 00:01:20 +0000
  Processing by PagesController#home as HTML
Rendered pages/home.html.erb within layouts/application (91.0ms)
Rendered layouts/_header.html.erb (3.0ms)
Rendered layouts/_footer.html.erb (1.0ms)
Completed 200 OK in 400ms (Views: 387.0ms | ActiveRecord: 12.0ms)
cache: [GET /assets/application-a05ca896e645eacb50266c7866d18a0f.css] miss, store


Started GET "/assets/application-a05ca896e645eacb50266c7866d18a0f.css" for 127.0.0.1 at 2011-12-20 00:01:21 +0000
Compiled application-a05ca896e645eacb50266c7866d18a0f.css  (4ms)  (pid 5912)
Compiled colours.css  (9ms)  (pid 5912)
Compiled custom.css  (0ms)  (pid 5912)
Compiled activity.css  (21ms)  (pid 5912)
Compiled jquery/jquery-ui-1.8.13.custom.css  (1ms)  (pid 5912)
Compiled ellib/elcommon.css  (0ms)  (pid 5912)
Compiled ellib/eldialogform.css  (1ms)  (pid 5912)
Compiled elrte/elrte.css  (1ms)  (pid 5912)
Compiled activities/text_editor.css  (0ms)  (pid 5912)
Compiled errors.activities.css  (1ms)  (pid 5912)
Compiled errors_and_notices.css  (0ms)  (pid 5912)
Compiled general.css  (0ms)  (pid 5912)
Served asset /application-a05ca896e645eacb50266c7866d18a0f.css - 200 OK (871ms)
cache: [GET /assets/application-9a36deba94d6308ab9bebe4e30a93959.js] miss


Started GET "/assets/application-9a36deba94d6308ab9bebe4e30a93959.js" for 127.0.0.1 at 2011-12-20 00:01:22 +0000
Compiled application-9a36deba94d6308ab9bebe4e30a93959.js  (9ms)  (pid 5912)
Compiled jquery.js  (13ms)  (pid 5912)
Compiled jquery_ujs.js  (1ms)  (pid 5912)
Compiled jquery-ui.js  (19ms)  (pid 5912)
Compiled AJP_main.js  (0ms)  (pid 5912)
Compiled ajp.utilities.js  (32ms)  (pid 5912)
Served asset /application-9a36deba94d6308ab9bebe4e30a93959.js - 304 Not Modified (110802ms)
cache: [GET /assets/logo_80px_80px-27d7b084daa398621574b10963529e84.png] miss


Started GET "/assets/logo_80px_80px-27d7b084daa398621574b10963529e84.png" for 127.0.0.1 at 2011-12-20 00:03:13 +0000
Served asset /logo_80px_80px-27d7b084daa398621574b10963529e84.png - 304 Not Modified (3ms)
cache: [GET /assets/hello.png] miss


Started GET "/assets/hello.png" for 127.0.0.1 at 2011-12-20 00:03:13 +0000
Served asset /hello.png - 404 Not Found (3ms)

ActionController::RoutingError (No route matches [GET] "/assets/hello.png"):


Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout
 (1.0ms)

. . . :-D & :-o ?

Edit 3 You don't need to run it once in production mode first (i.e. it's actually the act of running in development, that does something to trigger the production mode to (?) re-precompile the assets). After using rake to precompile the assets, it just needs to be run in development mode, request a page (which is necessary), then run in production and requesting home page again is enough for it to trigger what seems like the second precompile.

This has now survived a complete reboot of my machine (win 7-64bit). So I think it's a consistent bug.

Is StackOverflow the best place to continue this discussion or is it best to go on to the Sprocket git-hub page, or something?

解决方案

I had the exact same issue, and solved it by changing this option to true (it is at false by default) in my production.rb file.

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = true

From what I understand, setting this option to false makes sense if you are running under Apache or nginx, which was not my case.

这篇关于application.css不作为资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆