Sha256: 60dcc8c2b6607f3fff1b445b6b173356a8b0543f0b3a14891ca3dd2947a67ebc

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Crumbs
  module Extensions
    module ActionController
      module Base
        extend ActiveSupport::Concern

        included do
          before_action :set_crumbs
        end

        private

        def set_crumbs
          paths = [request.path]
          until paths.first == '/'
            paths.prepend File.dirname(paths.first)
          end
          session[:referers] ||= {}
          url, query = request.url.split(/\/?\?/)
          if query
            session[:referers][url] = query
          end
          @crumbs = []
          paths.each do |path|
            url = "#{request.base_url}#{path}".remove(/\/$/)
            begin
              params = Rails.application.routes.recognize_path(url)
            rescue
              next
            end
            if name = Crumbs.definitions.find("#{params[:controller]}##{params[:action]}", params)
              if query = session[:referers][url]
                url << "?#{query}"
              end
              @crumbs << { name: name, url: url }
            end
          end
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
crumbs-5.1.1 lib/crumbs/extensions/action_controller/base.rb
crumbs-5.1.0 lib/crumbs/extensions/action_controller/base.rb
crumbs-4.0.0.1 lib/crumbs/extensions/action_controller/base.rb
crumbs-4.0.0.0 lib/crumbs/extensions/action_controller/base.rb