我有app/assets/index.html.erb
包含<%= 'Hello world!' %>
,并添加 require "sprockets/railtie"
至config/application.rb
但是当我运行rake assets:precompile
时( RAILS_ENV=development
) public/assets
保持空状态。
我缺少什么?
我也在使用webpacker
并且没有使用sprockets
最初。
最佳答案
观看次数不是 Assets 。每次当 Rails 处理 HTTP 请求时,您的 View 模板(erb、slim 等)都会被编译和渲染。了解有关 Rails View 的更多信息 here .
Assets 仅包括 css、js、字体、图像等。如果 Assets 文件夹中没有任何 Assets 文件,则“rake assets:precompile”将不会执行任何操作。有关 Assets 管道的更多信息 here .
UPD。 May be this solution helps for you.
UPD2。
- 我使用 <%= "Hello, world!"%> 创建文件
assets/html/index.html.erb
。 - 我将以下行添加到我的
config/application.rb
中:
config.assets.precompile = ['*.js', '*.css', '*.html.erb']
- 我将以下行添加到我的manifest.js
//= link_directory ../html .html
- 我运行
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
...
- 我打开编译的文件并看到“Hello, world”
关于ruby-on-rails - Rails 预编译index.html.erb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55439476/