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?

Craig McGuff
  • 3,968
  • 6
  • 30
  • 35

1 Answers1

0

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?

Craig McGuff
  • 3,968
  • 6
  • 30
  • 35