Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7068749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:21:44+00:00 2026-05-28T05:21:44+00:00

My Problem We are developing a locally-hosted web application for small businesses. We also

  • 0

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

This is an idea I got from octopus, which is a database sharding gem. I’ve looked around in their source code, and it looks pretty hairy. They pretty much go elbow-deep into ActiveRecord, hijacking the DB connection, etc. I’m hoping that is overkill for what I want. Any advice on how MagicalClass might work? 🙂

Rails 3.1.0
ActiveRecord 3.1.0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:21:44+00:00Added an answer on May 28, 2026 at 5:21 am

    There are patches to allow default scopes to take procs see here for details, and it may work now without any of the patches/gems.

    That combined with Thread.current may be enough to get you going.

    That said… might it make more sense to take a multi-tenant approach with separate DBs altogether?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem developing/optimizing a web page. I know it is good
I am developing an xbap application and have run into a problem with users
We're developing a ASP.Net Web Application project that has a Silverlight 2.0 component. We've
I am facing a problem on developing my web app, here is the description:
I've encountered an interesting problem while developing for our legacy XWindows application. For reasons
i have a problem i am developing an asp.net mvc project. Website is in
Currently developing a PHP framework and have ran into my first problem. I need
I'm developing an Eclipse plug-in and I have a problem which is reproduced here:
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
I'm developing a custom autocomplete control in pure WinApi, and the problem that I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.