ryanb / cancan

Authorization Gem for Ruby on Rails.
MIT License
6.27k stars 783 forks source link

Ask subjects which subject rule should match against #877

Open kwando opened 11 years ago

kwando commented 11 years ago

It would be nice to have CanCan could ask the subject which it should match against, like the following code.

class BlogPost < ActiveRecord::Base
end

class BlogPostPresenter < SimpleDelegator
  def cancan_subject # <-- bad name for the hook...
     __getobj__
  end
end

# in some view file
@presented_blog_post = BlogPostPresenter.new(@blog_post)

# it would be awesome if both of these worked
can? :update, @blog_post
can? :update, @presented_blog_post  

Right now I need to know if I pass a decorated/presented object into the cancan call or not. Ask me if anythings is unclear and pardon me if this feature already exists (could not find any reference to it).

kwando commented 11 years ago

I figured out that if I delegate the class instance method to the delegated object it all works as I want..

xhoy commented 10 years ago

Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013. Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan.

We hope to see you on the other side!