Sha256: 7bc84d4bb0acf190cb7a9b473469b05bb4ec095a75b829622877513bebaa695b

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

class ActionController::Base
  def self.whitelist_actions(*names)
    extend WhitelistActions
    include WhitelistControllerActions

    before_filter :verify_whitelisted_actions

    actions *names
  end

  module WhitelistControllerActions
    def verify_whitelisted_actions
      return if self.class.name.starts_with?("Clearance::")

      valid_actions = self.class.whitelisted_actions
      return if valid_actions == :skip || valid_actions.include?(action_name)

      unless Rails.env.development?
        error 404, "This page doesn't exist"
        return
      end

      
      msg = <<-TEXT
No such action exists: #{controller_name}##{action_name}.
Note: this application uses the whitelisted_actions plugin,
you might have to use the 'actions' method to whitelist your actions.
TEXT

      logger.warn msg
      error 404, msg
    end
  end
  
  module WhitelistActions
    def whitelisted_actions
      @whitelisted_actions ||
      (superclass.respond_to?(:whitelisted_actions) ? superclass.whitelisted_actions : nil)
    end
    
    def skip_whitelist_actions
      @whitelisted_actions = :skip
    end
    
    def actions(*names)
      @whitelisted_actions = names.map(&:to_s).to_set
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vex-0.6.2 lib/vex/action_controller/whitelisted_actions.rb