Sha256: a27f4e01cc3516101e79aa7bd09f4247d5c22f6ca0b5f8f77f618ed66a628642

Contents?: true

Size: 1.66 KB

Versions: 39

Compression:

Stored size: 1.66 KB

Contents

class JefferiesTube::ErrorsController < ApplicationController
  if Rails.version.start_with? "3"
    before_filter :disable_pundit
    skip_before_filter :verify_authenticity_token
  else
    before_action :disable_pundit
    skip_before_action :verify_authenticity_token
  end

  def render_404
    log_404
    render_error_page 404
  end

  def additional_information
    # TODO not implemented yet
    render text: "Thanks!", layout: has_app_layout?
  end

  private
  def render_error_page(code)
    request.format = :html unless [:html, :json, :xml].include? request.format.to_sym
    respond_to do |format|
      format.any do
        begin
          render template: "/errors/#{code}", layout: has_app_layout?, status: code
        rescue #ActionView::MissingTemplate
          # Failsafe
          render template: "/errors/#{code}", layout: false, status: code
        end
      end
    end
  end

  def log_404
    if defined?(Rollbar) && request.referrer.present?
      Rollbar.warn("Got 404 with referrer", referrer: request.referrer, current_path: request.path)
    end
  end

  def disable_pundit
    if defined?(Pundit)
      skip_authorization
    end
  end

  def has_app_layout?
    if Gem::Version.new(Rails.version) >= Gem::Version.new("5")
      !!self.send(:_layout, [request.format.to_sym])
    else
      # boolean based on if there is a default layout for the current mime type
      !!self.send(:_layout)
    end
  end

  def html_layout
    if Gem::Version.new(Rails.version) >= Gem::Version.new("5")
      self.send(:_layout, ["html"]).virtual_path
    else
      # boolean based on if there is a default layout for the current mime type
      "application"
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
jefferies_tube-1.2 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-1.1.1 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-1.1.0 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-1.0.5 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-1.0.4 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-1.0.3 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-1.0.2 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-1.0.1 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-1.0.0 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.9 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.8 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.7 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.6 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.5 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.4 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.3 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.2 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.1 app/controllers/jefferies_tube/errors_controller.rb
jefferies_tube-0.1.0 app/controllers/jefferies_tube/errors_controller.rb