0

index.htmlRails 4 アプリケーションのディレクトリにファイルを配置しましたpublicが、この削除されたファイルがまだ Rails ウェルカム ページとして表示されます。開発モードで Webrick を使用しています。セットアップがほぼ同じで、正常に動作する別のアプリがあります。

4

3 に答える 3

3

上記のように、Rails 4 では /public フォルダーのデフォルトの index.html ページが削除されました。とにかく機能を実現したい場合は、ページを手動でレンダリングする必要があります。コントローラーを作成し、選択したコントローラー アクションで次のようにインデックス ページをレンダリングするだけです。

def index
  render :file => 'public/index.html' and return
end

編集: Rails スタックを使用せずにファイルを提供する場合は、そのように Web サーバー (Apache/Nginx/whatever) を構成する必要があります。NginxおよびApacheの構成。serve_static_assetsさらに、 Falseに設定して、設定で Rails の静的ファイル レンダリングを無効にする必要があります。

config.serve_static_assets configures Rails itself to serve static assets. Defaults
to true, but in the production environment is turned off as the server software (e.g.
Nginx or Apache) used to run the application should serve static assets instead.
Unlike the default setting set this to true when running (absolutely not recommended!)
or testing your app in production mode using WEBrick. Otherwise you won´t be able use
page caching and requests for files that exist regularly under the public directory
will anyway hit your Rails app.

したがって、これを開発モードで使用する場合は、 でconfig.serve_static_assetsfalse に設定しますenvironments/development.rb

于 2013-09-10T11:36:25.143 に答える
1

Rails 4 は動的な index.html を使用します。http://blog.remarkablelabs.com/2012/12/dynamic-index-html-rails-4-countdown-to-2013を読む

于 2013-09-08T17:23:14.030 に答える
0

ナビゲーターで F5 キーを押すと、インデックスをキャッシュに入れることができます。

于 2013-09-08T14:41:40.930 に答える