sorry, didint mention why it was a bad idea. Just in case the root user changes id. or someone can modify the parameters and pretend to be of id 1. and probably for som many reasons i forgot right now.
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 -~----------~----~----~----~------~----~------~--~---

