Skip to content

Not working from inside engine controller #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JakeTheSnake3p0 opened this issue Apr 26, 2017 · 0 comments
Open

Not working from inside engine controller #44

JakeTheSnake3p0 opened this issue Apr 26, 2017 · 0 comments

Comments

@JakeTheSnake3p0
Copy link

JakeTheSnake3p0 commented Apr 26, 2017

I want to cache my http status response pages, and I use my mountable engine to generate those pages for each of my applications. The problem is that nothing gets cached. I've verified that the controller method is being executed as I actually do get the fully generated HTML response; it's just that the file isn't saved to /public. You'll note below that I attempt to log the public directory inside the page_cache_directory proc but I don't see any logs written either.

Main app:

config/application.rb: config.exceptions_app = routes


Engine:

lib/manager/engine.rb: (don't know for sure if this is what I need to require, so I tried both)

require 'actionpack/page_caching'
require 'action_controller/page_caching'

Routes:

%w(401 403 404 410 422 500).each do |code|
  get code, to: 'errors#show', as: "error_#{ code }", code: code
end

ErrorsController:

require_dependency 'manager/application_controller'
module Manager
  # Raise templated HTTP response pages
  class ErrorsController < ApplicationController
    skip_before_action :login_required
    skip_before_action :find_model

    self.page_cache_directory = -> { Rails.logger.debug Rails.root.join('public').inspect; return Rails.root.join('public') }
    caches_page :show

    def show
      render_status params[:code]
    end

    protected

    def render_status(status = 500)
      status = status.to_i
      respond_to do |format|
        format.any(:html, :shtml) do
          render "#{ status }.html", status: status
        end
      end
    rescue ActionController::UnknownFormat, ActionView::MissingTemplate
      head status: status
    end
  end
end

I also call caches_page directly in one of the main application's controller and it works. It's just from within the rails engine that it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant