Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NaN1488/5781517 to your computer and use it in GitHub Desktop.
Save NaN1488/5781517 to your computer and use it in GitHub Desktop.
authorized_inherited_resources with cancan
class ApplicationController < ActionController::Base
# Add this to your application_controller
def self.authorized_inherited_resources
inherit_resources
before_filter :authorize_resource_with_cancan
define_method(:authorize_resource_with_cancan) do
case action_name.to_sym
when :new, :create
authorize!(action_name.to_sym, build_resource)
when :show, :edit, :destroy
authorize!(action_name.to_sym, resource)
else
authorize!(action_name.to_sym, resource_class)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment