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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:51:19+00:00 2026-06-08T09:51:19+00:00

I have a category model default_scope :order => ‘display_order asc’ has_many :resources, :dependent =>

  • 0

I have a category model

   default_scope :order => 'display_order asc'
   has_many :resources, :dependent => :destroy

# == Schema Information
#
# Table name: categories
#
#  id          :integer(4)      not null, primary key
#  name        :string(255)
#  description :string(255)
#  created_at  :datetime        not null
#  updated_at  :datetime        not null
#

I have a resources model:

belongs_to :category
  # belongs_to :submitter, :class_name => 'User', :foreign_key => "submitter_id"
  has_and_belongs_to_many :filetypes
  has_many :users, :through => :kits
  has_many :kits
  belongs_to :submitter, class_name: "User"
  belongs_to :author

== Schema Information

#
# Table name: resources
#
#  id                 :integer         not null, primary key
#  title              :string(255)
#  url                :string(255)
#  description        :string(255)
#  price              :decimal(, )
#  created_at         :datetime        not null
#  updated_at         :datetime        not null
#  category_id        :integer
#  image_file_name    :string(255)
#  image_content_type :string(255)
#  image_file_size    :integer
#  image_updated_at   :datetime
#  status             :string(255)
#  submitter_id       :integer
#  author_id          :integer
#

The client wants to be able to create categories but assign different attributes to the resource depending on the category.

Example:
category created: ‘Books’
He would like to have fields ‘author’ for example stored in the Resource model.

category created: ‘Conference’
He would like to have fields ‘location’, ‘date’ for example stored in the Resource model.

How can I model this so its dynamic and easy to maintain in the long term?

  • 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-08T09:51:21+00:00Added an answer on June 8, 2026 at 9:51 am

    One idea would be to have a separate table just for the fields of a category. For example, your setup could look something like this:

    category HABTM category_fields
    category_field HABTM categories
    category_field has_many category_field_values
    category_field_value belongs_to category_field
    

    Then, when your client created a new category, i.e. Books, he could add a new category_field to that category called author. Then if he wanted to add a new author to the Books category, he would add a category_field_value (i.e. JK Rowling) to the author category_field.

    Thus,
    the Books category would have an author category_field, and the author category_field would have one category_field_value (JK Rowling).

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

Sidebar

Related Questions

I have a model with a relationship like this: class Category < ActiveRecord::Base has_many
I have a model # == Schema Information # # Table name: posts #
I have following models: class Category < ActiveRecord::Base has_many :items default_scope where(:enabled => true,
I have a Category model which uses acts_as_tree class Category < ActiveRecord::Base acts_as_tree :order=>name
I have a model Category, which has_many Products, and a Product in turn has_many
I have category model that has a tree structure. In my database I have
I have a auction model and a category model. Auction belongs_to category and category
I have a Category and a Post model, with each Post belonging to a
I have one model User and will be creating another one Category . Both
I have 3 models: Category, Account, and SubAccount The relations are: Accounts has_many :sub_accounts

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.