Rails预编译index.html.erb

问题描述 投票:0回答:1

我有app/assets/index.html.erb包含<%= 'Hello world!' %>,并添加require "sprockets/railtie"config/application.rb,但当我运行rake assets:precompileRAILS_ENV=developmentpublic/assets保持空。我错过了什么?我也使用webpacker并且最初没有使用sprockets

ruby-on-rails ruby asset-pipeline erb sprockets
1个回答
3
投票

观点不是资产。每次rails处理HTTP请求时,都会编译和呈现您的视图模板(erb,slim等)。阅读更多关于Rails视图here的信息。

资产仅包括css,js,字体,图像等。如果资产文件夹中没有任何资产文件,则“rake assets:precompile”将不执行任何操作。更多关于资产管道here

UPD。 May be this solution helps for you.

UPD2。

  1. 我创建文件assets/html/index.html.erb
  2. 我在config/application.rb上添加了以下行:
config.assets.precompile = ['*.js', '*.css', '*.html.erb']
  1. 我在manifest.js中添加了跟随行
//= link_directory ../html .html
  1. 我运行rake assets:precompile并看到:
...
I, [2019-03-31T13:56:28.979563 #50803]  INFO -- : Writing rails_app/public/assets/index-f4e7c3b6ac0beff671efa8cf84639011c06e58ca53a78d83f36107316cec125f.html
I, [2019-03-31T13:56:28.979832 #50803]  INFO -- : Writing rails_app/public/assets/index-f4e7c3b6ac0beff671efa8cf84639011c06e58ca53a78d83f36107316cec125f.html.gz
...
  1. 我打开编译文件,看看“Hello,world”
© www.soinside.com 2019 - 2024. All rights reserved.