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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:15:02+00:00 2026-06-08T07:15:02+00:00

I plan on giving different logic to different categories and I don’t know if

  • 0

I plan on giving different logic to different categories and I don’t know if I should make 20 different models or if I can have just one StoreCategory model and put the logic in there. Some of the logic will be small and others large.

So If I had different store categories like discount, online, delivery, retail, etc, and wanted to give them their own special logic, what should I do?

  • 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-06-08T07:15:04+00:00Added an answer on June 8, 2026 at 7:15 am

    It’s a good question. In your place, I would create a class “Category” and my other classes inherit from the first. In the Category class I would put the shared code and the specific code in subclasses. You could use polymorphic associations if it’s necessary. It’s just an idea.

    Edit 1 : Add code example

    class StoreCategory < ActiveRecord::Base
    
      before_save :something_private
    
      def a_public_function
        #...
      end
    
      protected 
        def a_protected_function
          #...
        end
    
      private
        def something_private
          #something after save
        end
    end
    
    class DiscountCategory < StoreCategory
      def my_first_function
        #I could use a_public_function and a_protected_function
      end
    end
    
    class OnlineCategory < StoreCategory
      def a_protected_function
        #I could use a_public_function
        #I could override a_protected_function
        #I could use super to run the Category's function
      end
    end
    

    the function something_private is called after the save of each subclasses. I think it’s clear and organisated. It works like ApplicationController class.

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

Sidebar

Related Questions

I plan to make an pretty big application on Facebook. Would it be a
I have HostGator Baby Shared Plan . I develop Drupal site on. everything was
I'm attempting to write a custom MarkupExtension to make my life easier by giving
While similiar questions have been asked, this one's focused on which is best/easiest to
I want to make a database that can store any king of objects and
In my app I have a table of venues where each can be on
I have a computer vision set up with two cameras. One of this cameras
I have a JSON object from the CrunchBase API giving me a bunch of
I plan on learning the ins and outs of mod_rewrite, but I have a
I am having two different sql queries one written by me and one automatically

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.