My Problem
We are developing a locally-hosted web application for small businesses. We also have a demo site that lets potential customers look around to evaluate the product. Right now, all customers using the demo site have access to the same data, which is less than ideal because they might be making modifications behind each others backs, which would make the app feel "unstable" if they noticed. I would like to give each customer their own data subset to improve their experience. Adding a user_id column to all my models is easy enough, but now I need to make sure all the queries use this new association.
The Hard Way of Solving My Problem
I could go through by hand and change a call like @people = Person.all
to @people = current_user.people
, but lame! Development is continuing on the master branch, and I don t want to have to babysit every query when I merge over to the demo branch.
What I d Like to do Instead
I would like to do create an around_filter in my application_controller that will grab my queries and add in this extra layer of scoping like so:
around_filter :scope_on_current_user def scope_on_current_user(&block) MagicalClass.scope_on_user(current_user, &bock) end
Rails 3.1.0
ActiveRecord 3.1.0