Sha256: 034b386bce7bb0cd70bfa3df6f6b676d556407a3646c03ef0fb635534d8aed5e

Contents?: true

Size: 776 Bytes

Versions: 5

Compression:

Stored size: 776 Bytes

Contents

# frozen_string_literal: true

module RailsMiniProfiler
  class ApplicationController < ActionController::Base
    rescue_from ActiveRecord::RecordNotFound, with: :not_found

    before_action :check_current_user

    protected

    def present(model, presenter_class = nil, **kwargs)
      klass = presenter_class || "RailsMiniProfiler::#{model.class.to_s.demodulize}Presenter".constantize
      presenter = klass.new(model, view_context, **kwargs)
      yield(presenter) if block_given?
      presenter
    end

    private

    def not_found(error)
      redirect_back(fallback_location: profiled_requests_path, alert: error.to_s)
    end

    def check_current_user
      redirect_back(fallback_location: root_path) unless User.get(request.env).present?
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_mini_profiler-0.3.0 app/controllers/rails_mini_profiler/application_controller.rb
rails_mini_profiler-0.2.1 app/controllers/rails_mini_profiler/application_controller.rb
rails_mini_profiler-0.2.0 app/controllers/rails_mini_profiler/application_controller.rb
rails_mini_profiler-0.1.3 app/controllers/rails_mini_profiler/application_controller.rb
rails_mini_profiler-0.1.2 app/controllers/rails_mini_profiler/application_controller.rb