views:

34

answers:

2

Just wondering if there is a plugin out there that abstracts the process of deriving the instance of a current resource (or its class) from the current controller name?

Currently I just classify.constantize the controller name, and if that works then I test for the id paramater and load the record if it exists.

Yea, maybe it's a bit weird, but just wondered if someone's been there before and done it properly.

The reason it exists is because I need to know these objects to perform authentication on a granular level but I have about 35 different object classes so it needs to be abstract. I suppose I could assign @item to be the current item in each controller and rely on that but it seems a but unDRY.

A: 

inherited_resources :)

amikazmi
Thanks, seems like an elegant solution. I had a look at the code and yep, they're just pulling off the controller_name which is what I'm already doing. Looks like that's the way. Since I don't need any of what that plugin offers I won't use it, but it was interesting to see the details :)
Brendon Muir
A: 

ResourceController by James Golick. It's out default in Blank, a starter application.

François Beausoleil
Thanks for this too :) Both good suggestions for leads :)
Brendon Muir