Permalink
Browse files

Automagically set the filter_access_to to work with namespaced contro…

…llers

Context by default is the controller_name.to_sym, however this breaks with the use of namespaced controllers (eg. Admin::FoozlesController)
Instead of taking controller_instance.class.controller_name, this change takes the controller_instance.class.name and gsubs :: into _ so the resulting symbols look like :admin_foozles rather than :foozles

This is a variant to the style implemented in viva-declarative_authorization:
http://github.com/viva/declarative_authorization/commit/f3376b1cf557e119511479acb2c702d9139d7c44#diff-0
  • Loading branch information...
Mark Connell
Mark Connell committed Oct 20, 2009
1 parent c6ee88e commit 1edc6d0399881c58fcf3325478869727cdbc9be1
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/declarative_authorization/in_controller.rb
@@ -545,7 +545,7 @@ def permit! (contr)
if @filter_block
return contr.instance_eval(&@filter_block)
end
context = @context || contr.class.controller_name.to_sym
context = @context || contr.class.name.gsub(/::/, '_').gsub(/Controller$/, "").underscore.to_sym
object = @attribute_check ? load_object(contr, context) : nil
privilege = @privilege || :"#{contr.action_name}"

0 comments on commit 1edc6d0

Please sign in to comment.