I am using cancan for authorization. I have a shared view which need authorize depending on which controller it is.
The problem is: I have shared partial (description.rhtml) and it is used by two different models (Product and Orders). So when some one go to
www.example.com/product/1 - description section shows description about product www.example.com/order/1 - description section shows description about order
This description section has edit button on it so the user can edit it but the condition is
- the user must be owner of the product when on product/1 page or
- owner of order when user is on order/1 page.
My ability class check for
if user is owner or not - depending on product or order controller However on view:
if (can? :update, @orders) || (can? :update, @product) < hide edit button > endbut if can? :update, @orders return true or false, it show or hides edit button depending on that condition only
So my question is how can make use CanCan to tackle this problem
Hope I was clear.