3

私は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 ファイルをロードします。

4

2 に答える 2

1

マニフェスト ファイルに関しては、デフォルトのままにしておくことをお勧めします。これらは、asset-pipeline の管理ポイントとなることを意図しています。あなたの場合、やるべきことがいくつかあります:

  • cssの定義をapplication.css別の css ファイルに移動します。app/assets/stylesheets

  • パーツを「マニフェスト」スタイルに含めます-それは奇妙なものです。行がコメントされていることがわかりますが、そうではありません。このような :

    *= require_self  
    *= require jquery 
    *= require jquery_ujs
    *= require_tree .
    
  • assets/stylesheetsあなたがやろうとしているのと同じように、新しいディレクトリで拡張している場合は、次のapplication.rbように言及することをお勧めします:

    config.assets.paths << Rails.root.join("app", "assets", "styleshhets", "modules")
    

最後の提案:public/assets開発環境で削除します。それは物事を無用に複雑にします。に頼るだけapp/assetsです。

于 2013-01-14T17:45:17.520 に答える
-2

アセットをプリコンパイルするためのセットalpha.rbconfig.assets.compiletrue

于 2013-01-14T17:39:24.343 に答える