10

アセットのコンパイルは正常に機能していますが、実行すると次のようになります。

thin start -e production

JavaScript や CSS が読み込まれていません。私のブラウザは、アセットを取得するためのリクエストもキャンセルしています。これがなぜなのかはわかりませんが、404 と考えているためだと思われます。一番上の画像を見ると、application.css ファイルがコンパイルされ、assets フォルダーに保存されていることがわかりますが、ファイルにアクセスしようとすると、404.html ファイルが取得されます。

何を与える!?

ここに画像の説明を入力

ここに画像の説明を入力

編集:

私の見解を掲載するよう求められました。プロジェクトのコードの一部を次に示します。

<% content_for :title, 'Quick Quote' %>
<% content_for :subtotal, get_subtotal %>
<% content_for :stylesheet_includes do %>
  <%= stylesheet_link_tag "quote", "jquery-ui-timepicker-addon" %>
<% end %>
<% if @quote.errors.any? %>
  <div class="flash alert">
  <% @quote.errors.full_messages.each do |msg| %>
    <div><%= msg %></div>
  <% end %>
  </div>
<% end %>
<h1>Quick Quote</h1>

私のレイアウト:

<!DOCTYPE html>
<html>
<head>
  <title><%= (yield(:title) + " - " unless yield(:title).blank?).to_s + "Online Scheduler Order Taker" %></title>
  <%= stylesheet_link_tag    "application", "jquery-ui-timepicker-addon.css", :media => "all" %>
  <%= yield :stylesheet_includes %>
  <%= javascript_include_tag "application" %>
  <%= yield :javascript_includes %>
  <%= csrf_meta_tags %>
</head>
<body>

私の production.rb のコード

config.assets.precompile += %w( quote.css jquery-ui-timepicker-addon.css prices.css contact.css )

私のapplication.css.scss.erbのトップ:

/*
 * 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 . <- commented out
 * require jquery-ui-timepicker-addon.css <- commented out
 */

私のapplication.jsファイル全体

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery-ui-timepicker-addon.js
//= require_tree .
4

4 に答える 4

10

ファイルを確認し、config/environments/production.rb次の行を追加します (まだ追加されていない場合)。

config.serve_static_assets = true
于 2013-04-30T09:46:23.730 に答える
10

Rails では、config.serve_static_assetsデフォルトでこの設定を無効にすること、つまり false に設定することを推奨しています。config/environments/production.rbRailsアプリで生成されたデフォルトの構成は次のとおりです

Rails の静的アセット サーバーを無効にします (Apache または nginx は既にこれを行っています)。

config.serve_static_assets = false

trueしたがって、ローカル アプリで に設定している場合でも問題ありません。ただし、アプリを Apache や ngix、または heroku 以外にデプロイする場合は、構成ファイルを作成することconfig.serve_static_assets=trueはお勧めできません。production.rbRailsガイドのドキュメントは次のとおりです。

config.serve_static_files は、静的ファイルを提供するように Rails 自体を構成します。デフォルトは true ですが、本番環境では、アプリケーションの実行に使用されるサーバー ソフトウェア (NGINX や Apache など) が代わりに静的アセットを提供する必要があるため、オフになっています。既定の設定とは異なり、WEBrick を使用してアプリを実行するとき (絶対にお勧めしません!)、または本番モードでアプリをテストするときは、これを true に設定します。そうしないと、ページ キャッシュを使用できず、パブリック ディレクトリに定期的に存在するファイルに対する要求がとにかく Rails アプリにヒットします。

URL - http://guides.rubyonrails.org/configuring.html

于 2015-05-12T18:05:43.897 に答える