Sha256: f0fc75bfd592f666661131bdef72361eba91c869f48e5f327683052efd078c24
Contents?: true
Size: 1.74 KB
Versions: 3
Compression:
Stored size: 1.74 KB
Contents
class SlicesController < ActionController::Base include ActiveSupport::Benchmarkable protect_from_forgery rescue_from Exception, with: :render_error rescue_from Page::NotFound, with: :render_not_found append_view_path(File.join(Rails.root, *%w[app slices])) around_filter :set_locale define_callbacks :render_page, terminator: "response_body" def self.should_raise_exceptions? Rails.application.config.consider_all_requests_local end protected def render_not_found(exception) raise exception if self.class.should_raise_exceptions? render_not_found!(exception) end def render_not_found!(exception) logger.warn "404: #{request.path} :: #{request.params.inspect}" render_page(Page.find_virtual('not_found'), 404) end def render_error(exception) raise exception if self.class.should_raise_exceptions? logger.warn "500: #{request.path} :: #{request.params.inspect}" render_page(Page.find_virtual('error'), 500) end private def render_page(page, status = 200) @page = page run_callbacks :render_page do ordered_slices = nil benchmark 'Page.ordered_slices' do ordered_slices = page_or_parent_slices end @slice_renderer = Slices::Renderer.new( controller: self, current_page: @page, params: params, slices: ordered_slices ) render text: '', layout: page_layout(@page), status: status end end def page_or_parent_slices @page.entry? ? @page.parent.ordered_set_slices : @page.ordered_slices end def page_layout(page) page.layout end def request_locale params[:locale] end def set_locale I18n.with_locale(request_locale || I18n.default_locale) do yield end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
slices-2.0.2 | app/controllers/slices_controller.rb |
slices-2.0.1 | app/controllers/slices_controller.rb |
slices-2.0.0 | app/controllers/slices_controller.rb |