Sha256: 87f436a8a9e06b1074fa7300c6f38778f8ded7399fd7c56b89202dcefbc04438
Contents?: true
Size: 1.51 KB
Versions: 2
Compression:
Stored size: 1.51 KB
Contents
require 'active_support/concern' module Georgia module Concerns module Frontendable extend ActiveSupport::Concern included do caches_action :show, cache_path: :page_cache_key.to_proc cache_sweeper :navigation_sweeper, only: :show # Loads the page according to request url # Restore the latest published revision of the given page def show if preview? prepare_preview else @page = Georgia::Page.from_url(params[:request_path]).published.first || not_found @page = Georgia::PageDecorator.decorate(@page) end end protected def preview? params[:r].present? end # Loads the page according to given id # Temporarily set the given revision to preview as the 'current_revision' def prepare_preview @page = Georgia::Page.from_url(params[:request_path]).first || not_found @page = Georgia::PageDecorator.decorate(@page) @page.current_revision = Georgia::Revision.find(params[:r]) authorize! :preview, @page end # Triggers a 404 page not found # Use when provided url doesn't match any the Georgia::Pages def not_found raise ActionController::RoutingError.new('Not Found') end def page_cache_key [Georgia::Page.where(url: "/#{params[:request_path]}").try(:first).try(:cache_key), I18n.locale].compact.join('/') end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
georgia-0.7.8 | app/controllers/georgia/concerns/frontendable.rb |
georgia-0.7.7 | app/controllers/georgia/concerns/frontendable.rb |