我有app/assets/index.html.erb
包含<%= 'Hello world!' %>
,并添加require "sprockets/railtie"
到config/application.rb
,但当我运行rake assets:precompile
(RAILS_ENV=development
)public/assets
保持空。我错过了什么?我也使用webpacker
并且最初没有使用sprockets
。
观点不是资产。每次rails处理HTTP请求时,都会编译和呈现您的视图模板(erb,slim等)。阅读更多关于Rails视图here的信息。
资产仅包括css,js,字体,图像等。如果资产文件夹中没有任何资产文件,则“rake assets:precompile”将不执行任何操作。更多关于资产管道here。
UPD。 May be this solution helps for you.
UPD2。
assets/html/index.html.erb
。config/application.rb
上添加了以下行:config.assets.precompile = ['*.js', '*.css', '*.html.erb']
//= 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
...