【发布时间】:2013-01-14 16:22:41
【问题描述】:
我是 Ruby 和 Rails 的新手,我已经考虑了好几天了,还没有找到解决方案。我的项目在我的开发环境中运行良好,但在我的 alpha 或生产环境中无法运行。
我的 app/assets/stylesheets 文件夹中有以下样式表:
app
--> assets
--> stylesheets
--> modules
--> _header.css.scss
--> _footer.css.scss
--> home.css.scss
--> user.css.scss
--> help.css.scss
当我尝试使用我的 alpha 环境(即通过运行 rails s --environment=alpha)时,我收到此错误:
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Home#index
Showing /app/views/home/index.haml where line #1 raised:
home.css isn't precompiled
我正在使用 stylesheet_link_tag('home') 将该样式表添加到我的视图中。
我的alpha.rb 文件有这个:
config.assets.compile = false
config.assets.precompile += %w( help.css home.css users.css )
config.assets.compress = true
config.assets.debug = false
我正在运行预编译任务(即rake assets:precompile RAILS_ENV=alpha)。该任务似乎工作正常。这是输出:
rake assets:precompile RAILS_ENV=alpha --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/ruby-1.9.3-p286/bin/rake assets:precompile:all RAILS_ENV=alpha RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Invoke rails_admin:disable_initializer (first_time)
** Execute rails_admin:disable_initializer
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
我的文件确实以/public/assets/ 结尾,/public/assets/manifest.yml 正在创建中,我的文件也列在其中:
application.css: application.css
help.css: help.css
home.css: home.css
users.css: users.css
如果我尝试访问服务器(通过转到http://localhost:3000),我会收到前面提到的AssetNotPrecompiledError 错误home.css;但是,http://localhost:3000/assets/home.css 确实返回了样式表。
AFAIK 生成此错误是因为 Rails 不知道 home.css 的位置;但是,它在manifest.yml 上列出,我认为它应该在那里寻找它。
如果您需要更多信息,我很乐意提供。这让我发疯了!
-- 编辑--
根据 Qumara SixOneTour 的要求,这是我的 application.css.scss:
@import 'modules/header';
@import 'modules/footer';
body {
background: $bgColor asset-url('bgFull.jpg', image) repeat-x center top;
}
div.main {
padding: 35px 30px;
background: $whitweColor;
margin-top: -3px;
padding-bottom: 30px;
@include border-bottom-left-radius(5px);
@include border-bottom-right-radius(5px);
h1 {
font-size: 2em;
}
h2 {
font-size: 1.5em;
}
}
@media only screen and (max-width: 767px) {
body {
background: $bgColor asset-url('bg.png', image) repeat-x;
}
}
基本上,我不使用清单,而是在每个视图中加载单独的 css 文件。
【问题讨论】:
-
你能发
application.css文件吗? -
我将其添加到问题中。提前致谢!
-
你有没有弄明白这件事?我在使用新的 Rails 3.1.11 应用时遇到了完全相同的问题,我什至得到了图像的 AssetNotPrecompiledError(位于 /app/assets/images 并预编译到 /public/assets)。
-
对不起@ilasno,我从来没有这样做过......这样的事情让我停止使用 Rails。我现在使用 Node.js 和 Express 的工作效率更高了。
标签: ruby-on-rails ruby-on-rails-3.2 asset-pipeline