简体   繁体   中英

Dynamic page caching failing in Rails 5

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?

Ok for anyone else who runs into this - the issue is a small change in Rails 5 with render text, in the controller example above it should now read:

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

Found here What to use instead of `render :text` (and `render nothing: true`) in rails 5.1 and later?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM