Pundit: Suggestion: load_resource / authorize_resource / load_and_authorize_resource

Created on 6 Feb 2016  路  6Comments  路  Source: varvet/pundit

Hi,

My guess is that this was probably discussed before, but just in case it wasn't - I would like to bring it up.

Was it ever considered to provide a functionality similar to the one provided by CanCanCan for automatically loading and authorizing resources in a controller?

In CanCanCan these provided methods save a lot of code duplication.

  • load_resource except: [:index]
  • authorize_resource except: [:create]
  • load_and_authorize_resource except: [:index]

For context, I should mention that I am currently attempting to switch from CanCanCan to Pundit, and these are the first things in CanCanCan that I miss. So much so, that I am considering first rolling my own such functions before continuing with the porting.

EDIT:
I now see this notion was rejected in #28

Most helpful comment

The PunditExtra gem is ready

It adds the load_resource and authorize_resource filters and can? / cannot? helpers, so CanCanCan fans can feel right at home.

Hope someone finds it useful.

All 6 comments

I am considering developing a separate gem for these features + for can? and cannot? view helpers. Any objections? Or any interest in adding these functions directly to pundit?

I stand by my opinion from #28, and there have been other discussions around these kinds of features in other issues. I do not believe they are a good fit for Pundit. I don't want to add them to the gem.

If you feel like developing your own gem, I think you definitely should. The ecosystem only gets richer through more options, if you have a good idea, sharing it is always great.

Understood, and makes total sense.

The PunditExtra gem is ready

It adds the load_resource and authorize_resource filters and can? / cannot? helpers, so CanCanCan fans can feel right at home.

Hope someone finds it useful.

Cool! Thanks for sharing!

@jnicklas May be worth asking, but is there a comprehensive list of such extensions? Might be worth making a wiki page for that sort of stuff.

Was this page helpful?
0 / 5 - 0 ratings