[英]Rails 5 - Google Page Speed Insights - Leverage Browser Caching
[英]Dynamic page caching failing in Rails 5
我正在將Rails 4.2的站點更新為5.1
在先前的設置中,我在生成的樣式表(每個租戶)上進行了頁面緩存,所有工作均正常進行。
升級到5.1后,它不再起作用
使用最新版本的actionpack-page_caching
緩存的樣式表的控制器如下所示:
class StylesheetsController < ApplicationController
caches_page :show, gzip: true
def show
@stylesheet = Stylesheet.find(params[:id])
respond_to do |format|
format.html
format.css { render text: @stylesheet.contents, content_type: "text/css" }
end
end
end
我在日志中收到以下錯誤:
ActionView::MissingTemplate - Missing template stylesheets/show, application/show with {:locale=>[:en], :formats=>[:css], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}. Searched in:
沒有物理模板,因為我是直接從樣式表模型渲染它的。 確認模型正在返回數據。
在開發中啟用了緩存。
在布局頁面中,對動態樣式表的引用為:
<link href="<%= dynamic_stylesheet %>.css" rel="stylesheet" type="text/css" />
並且helper方法(在application_helper中)為:
def dynamic_stylesheet
stylesheet_path(current_account.stylesheet) unless current_account&.stylesheet&.id.nil?
end
我不確定在這里跳過/遺漏了什么指針嗎?
對於遇到此問題的任何人來說都很好-問題是Rails 5中帶有渲染文本的一個小變化,在上面的控制器示例中,現在應該顯示為:
format.css { render plain: @stylesheet.contents, content_type: "text/css" }
在Rails 5.1和更高版本中,可以使用什么代替“ render:text”(和“ render none:true”)?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.