index.html
Rails 4 アプリケーションのディレクトリにファイルを配置しましたpublic
が、この削除されたファイルがまだ Rails ウェルカム ページとして表示されます。開発モードで Webrick を使用しています。セットアップがほぼ同じで、正常に動作する別のアプリがあります。
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_assets
false に設定しますenvironments/development.rb
。
Rails 4 は動的な index.html を使用します。http://blog.remarkablelabs.com/2012/12/dynamic-index-html-rails-4-countdown-to-2013を読む
ナビゲーターで F5 キーを押すと、インデックスをキャッシュに入れることができます。