-
-
Save NaN1488/5781517 to your computer and use it in GitHub Desktop.
authorized_inherited_resources with cancan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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