1

I'm updating a site from rails 4.2 to 5.1

In the previous setup I have page caching on a generated stylesheet (per tenant), all working perfectly.

After upgrading to 5.1 this is no longer working

Using latest version of actionpack-page_caching

Controller for the Stylesheet that is cached looks like this:

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

I'm getting the following error in the logs:

ActionView::MissingTemplate - Missing template stylesheets/show, application/show with {:locale=>[:en], :formats=>[:css], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}. Searched in:

There is no physical template for this as I'm rendering it directly from the stylesheet model. Have confirmed the model is returning data.

Caching is enabled in development.

In the layout page the reference to the dynamic stylesheet is:

<link href="<%= dynamic_stylesheet %>.css" rel="stylesheet" type="text/css" />

and the helper method (in application_helper) is:

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

I'm not sure what's getting skipped/missed here, any pointers?

4

1 回答 1

0

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

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

在这里找到在 Rails 5.1 及更高版本中使用什么来代替`render :text`(和`render nothing: true`)?

于 2019-03-17T21:48:18.233 回答