Rails 5中的动态页面缓存失败

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

我正在从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" />

和辅助方法(在application_helper中)是:

def dynamic_stylesheet
  stylesheet_path(current_account.stylesheet) unless current_account&.stylesheet&.id.nil?
end

我不确定这里有什么被跳过/错过,任何指针?

ruby-on-rails-5 page-caching
1个回答
0
投票

对于遇到此问题的其他任何人都可以 - 问题是Rails 5中有一个带有渲染文本的小改动,在上面的控制器示例中它现在应该是:

format.css { render plain: @stylesheet.contents, content_type: "text/css" }

在这里找到What to use instead of `render :text` (and `render nothing: true`) in rails 5.1 and later?

© www.soinside.com 2019 - 2024. All rights reserved.