Search code examples
ruby-on-rails-3declarative-authorizationrails-cells

Cells with Declarative_Authorization


using the gems cells and declarative_authorization (along with Devise) and I'm trying to figure out how to include the permitted_to? into the cell templates. So far I've added this to my cells Cell (the Devise one works for it's helpers):

class SidebarCell < Cell::Rails
    include Devise::Controllers::Helpers
    helper_method :current_user
    include Authorization::AuthorizationHelper
    helper_method :permitted_to?



  def display(args)
    @object = args[:object]
    @notice = args[:notice]
    @alert = args[:alert]
    render
  end

end

But it's bombing at the fact that declarative_auth helper module uses the following code:

def permitted_to? (privilege, object_or_sym = nil, options = {}, &block)
      controller.permitted_to?(privilege, object_or_sym, options, &block)
    end

and obviously this gives

undefined local variable or method `controller' for ...

UPDATE:

After some more thinking, I'm not sure this would ever work with Cells. Declarative_auth needs the controller to base it's rules on, but Cells has nothing to do with that controller. It would seem to me that the two are incompatible, unless I pass a reference to the controller into Cells? Starting to think that Cells isn't the way to go.


Solution

  • This will work if you add

    helper_method :controller
    

    that just delegates:

    def controller
      parent_controller
    end
    

    Sorry for that inconvenience, but the entire helper architecture in Rails sucks: http://nicksda.apotomo.de/2011/10/rails-misapprehensions-helpers-are-shit/