Permalink
Browse files

Plugins: make auth! work for engines

If the model and the engine are in the same module, this makes auth!
from the main application work reliably when used in the controllers for
engine resources. Should have no effect on main application's auth.

Continuing work on #231 ...
  • Loading branch information...
1 parent a51bdb4 commit f49fc7cd3671a301bab7d66dabce9eac47c2bcf0 @mikldt mikldt committed Dec 28, 2012
Showing with 4 additions and 1 deletion.
  1. +4 −1 app/controllers/application_controller.rb
@@ -115,7 +115,10 @@ def auth!(opts = {})
if ((object.is_a? Enumerable) || (object.is_a? ActiveRecord::Relation))
object.delete_if {|o| cannot?(test_action, o)}
if new_exception && object.empty?
- new_object = controller_name.singularize.classify.constantize.new
+ # Parent will be Object for Concerto, or the module for Plugins.
+ new_parent = self.class.parent.name
+ new_class = new_parent + '::' + controller_name.singularize.classify
+ new_object = new_class.constantize.new
return true if can?(:create, new_object)
end
if !allow_empty && object.empty?

0 comments on commit f49fc7c

Please sign in to comment.