簡體   English   中英

Rails預編譯index.html.erb

[英]Rails precompile index.html.erb

我有app/assets/index.html.erb包含<%= 'Hello world!' %> <%= 'Hello world!' %> ,並且require "sprockets/railtie"config/application.rb但是當我運行rake assets:precompileRAILS_ENV=developmentpublic/assets保持為空。 我錯過了什么? 我也在使用webpacker ,最初沒有使用sprockets

觀點不是資產。 每次rails處理HTTP請求時,都會編譯和呈現您的視圖模板(erb,slim等)。 在此處閱讀有關Rails視圖的更多信息

資產僅包括css,js,字體,圖像等。如果資產文件夾中沒有任何資產文件,則“rake assets:precompile”將不執行任何操作。 更多關於資產管道的信息

UPD。 可能這個解決方案對您有所幫助。

UPD2。

  1. 我用<%=“Hello,world!”%>創建文件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”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM