RAILS_ENV 更改内容 app/layouts/application.html.erb 内容

RAILS_ENV changing the content of app/layouts/application.html.erb content

我正在开发一个 rails 应用程序,并且最近将 app/layouts/application.html.erb<%= javascript_include_tag "application" %> 行移动到了 </body> 标签的正下方。

当我以开发模式启动服务器并查看 localhost:3000 的源代码时,我按预期看到了结束正文标记下方的 javascript。但是,当我在生产模式下启动服务器时,javascript 出现在它原来的位置,在 <head> 标记中。

其他人是否知道在 development/production 环境中可能导致对 app/layouts/application.html.erb 文件的这种不同解释的原因?其他人可以提供的任何指示将不胜感激。

来自Rails guide on caching

This is an introduction to three types of caching techniques: page, action and fragment caching. By default Rails provides fragment caching. In order to use page and action caching you will need to add actionpack-page_caching and actionpack-action_caching to your Gemfile.

By default, caching is only enabled in your production environment. To play around with caching locally you'll want to enable caching in your local environment by setting config.action_controller.perform_caching to true in the relevant config/environments/*.rb file:

config.action_controller.perform_caching = true

您只需要清除缓存文件,因为 rails 在生产环境中默认缓存这些文件。