Sha256: 654897205470363bacf00089644ae62a0eee6e571f79e172b36d22389fab29c8

Contents?: true

Size: 665 Bytes

Versions: 10

Compression:

Stored size: 665 Bytes

Contents

require 'active_support/concern'

module Georgia
  module Concerns
    module Helpers
      extend ActiveSupport::Concern

      included do
        helper_method :instance_name
        helper_method :model
      end

      def instance_name
        controller_name.singularize
      end

      def model
        begin
          self.class.to_s.gsub(/Controller/,'').singularize.constantize
          # If no constant is found, check if the non-namespaced one exists. i.e. Partner => Admin::PartnersController
        rescue NameError
          self.class.to_s.gsub(/Controller/,'').gsub(/\w+::/,'').singularize.constantize
        end
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
georgia-0.8.0 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.8 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.7 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.6 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.5 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.4 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.3 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.2 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.1 app/controllers/georgia/concerns/helpers.rb
georgia-0.7.0 app/controllers/georgia/concerns/helpers.rb