Sha256: c59d2a1336f67967b2078f3be90d19a1b53b54d0fa9d82b639fa07352739b8ce

Contents?: true

Size: 938 Bytes

Versions: 7

Compression:

Stored size: 938 Bytes

Contents

module Pbw
  class ApplicationController < ActionController::Base
  	  
  	  rescue_from ::CanCan::AccessDenied do |exception|
	    respond_to do |format|
	    	format.json {render json: {:error => exception.message}, status: 401}
	    	format.html {redirect_to root_path, :error => exception.message}
	    end
	  end

	  rescue_from Mongoid::Errors::DocumentNotFound do |exception|
		respond_to do |format|
			format.html {redirect_to root_url, :error => exception.message}
			format.json {render json: {:error => exception.message}, status: 404}
		end
	  end

	  protected

	  def self.permission
	    return name = self.name.gsub('Controller','').singularize.split('::').last.constantize.name rescue nil
	  end

	  def current_ability
	    @current_ability ||= Ability.new(current_user)
	  end

	  def load_permissions
	    @current_permissions = current_user.role.permissions.collect{|i| [i.subject_class, i.action]}
	  end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pbw-0.0.9 app/controllers/pbw/application_controller.rb
pbw-0.0.8 app/controllers/pbw/application_controller.rb
pbw-0.0.7 app/controllers/pbw/application_controller.rb
pbw-0.0.6 app/controllers/pbw/application_controller.rb
pbw-0.0.5 app/controllers/pbw/application_controller.rb
pbw-0.0.4 app/controllers/pbw/application_controller.rb
pbw-0.0.3 app/controllers/pbw/application_controller.rb