I think you have a design problem here. Access controll should be
handled in the controller, not the model.
besides, having
def root?
id == 1
end
i believe is a very bad bad idea, maybe im wrong. any opinions anyone?
On Mar 16, 3:40 pm, Andrew France <[email protected]> wrote:
> Hi,
>
> Does anyone know a good way to override AR associations to take
> special cases into account. My current take is the example below which
> allows the 'root' user to access all products, but only works if I
> remember to call it with a .all/.find or similar method:
> 'user.products.all' instead of 'user.products'. Ideally I guess I want
> to return a proxy object that represents all products. Any ideas?
>
> class User
> has_many :products
>
> def root?
> id == 1
> end
>
> def products_with_root
> if root?
> Product # Better way?
> else
> products_without_root
> end
> end
> alias_method_chain :products, :root
> end
>
> Best regards,
> Andrew France
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---