私はRubyとRailsの両方に不慣れで、これについて何日も熟考してきましたが、解決策が見つかりませんでした. プロジェクトは開発環境では問題なく動作しますが、アルファ版または実稼働環境では動作しません。
app/assets/stylesheets フォルダーに次のスタイルシートがあります。
app
--> assets
--> stylesheets
--> modules
--> _header.css.scss
--> _footer.css.scss
--> home.css.scss
--> user.css.scss
--> help.css.scss
アルファ環境を (つまり、 を実行して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
スタイルシートは返します。
私の知る限り、このエラーは 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 ファイルをロードします。