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 4120534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:14:05+00:00 2026-05-20T23:14:05+00:00

I am building a rails 3 App. I’ll try to describe this application to

  • 0

I am building a rails 3 App. I’ll try to describe this application to the best of my ability and as succinctly as possible.

The two main types of models in this app are:

  • Users
  • Businesses

Then there are two other models:

  • Categories
  • Subcategories (nested within
    Categories)

How they work together is: the Businesses can have (or belong to, rather) as many categories as they like (and any related subcategories as well).

The user can chose categories to “follow”, i.e. they select the categories that they want to show up in their feed, and any businesses that belong to these categories will show up in the feed (same with subcategories)

It’s important to note that the categories and subcategories will be dictated by the admins only, the users/businesses can’t add/destroy categories, only follow existing ones

My plan for how to implement this was to create a “Following” model with the following attributes

  • user_id
  • followable_id
  • followable_type

of which there would be two “followable_types”: user, and business. As you can see this is a not-quite polymorphic model.

Where I am running into trouble is the methods. For example, how would I create a list of all the businesses that belong to the categories the user is following? It would require some tricky queries and a lot of hackery. This leads me to believe I am approaching the problem from the wrong angle.

Could someone steer me in the right direction? Maybe my architecture needs some work. Or give me a hint as to how I should be writing my methods.

Thanks!!

  • 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-20T23:14:06+00:00Added an answer on May 20, 2026 at 11:14 pm

    Given the queries you’ll be regularly performing I would probably do away with the polymorphism in this case and do something like:

    class Customer < ActiveRecord::Base
      has_and_belongs_to_many :categories
    end
    
    class Business < ActiveRecord::Base
      has_and_belongs_to_many :categories
    end
    
    class Categories < ActiveRecord::Base
      has_and_belongs_to_many :customers
      has_and_belongs_to_many :businesses
    end
    

    Then the code to perform the query you suggested is pretty simple:

    Business.joins(:categories).where('categories.id IN (?)', a_user.categories.map(&:id))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently building a Rails app, and trying to figure out the best
Im building a Rails app, and there are two models that I want to
Ok so I am building this rails app. I need a relationship between restaurants
I'm building a Rails app that has Etsy.com style functionality. In other words, it's
So I'm building a rails app for high school students and I've hit a
I'm building a Rails app to track expenses/debts among members of a group, let's
I'm building a Rails app which creates a bookmarklet file for each user upon
I am building a Rails app, and it seems that common practice is to
I am building a small rails app and I need a way to generate
I'm building a rails gallery app for a company that doesn't want to host

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.