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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:49:17+00:00 2026-06-13T05:49:17+00:00

Some models require other models to be loaded first. But each required file only

  • 0

Some models require other models to be loaded first. But each required file only needs to be loaded once.

What is the best way to manage this? Put all the require lines in a file (like init.rb), or require files at the top of each model file?

  • 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-13T05:49:18+00:00Added an answer on June 13, 2026 at 5:49 am

    Let’s evaluate each option:

    1. Put all the require lines in a file (like init.rb)

      This means each individual file will be less cluttered, as requires will all be in one place. However, it can happen that the order in which they are written matters, so you end up effectively doing dependency resolution manually in this file.

    2. require files at the top of each model file

      Each file will have a little more content, but you won’t have to worry about ordering as each file explicitly requires the dependencies it needs. Calling require for the same file multiple times has no effect.

      This also means that you can require only parts of your code, which is useful for libraries; e.g. require active_support/core_ext/date/calculations gets only the part of the library the external app needs.

    Of the two, I’d pick the second. It’s cleaner, requires less thinking, and makes your code much more modular.

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

Sidebar

Related Questions

I've encountered some problems with MongoID. I have three models: require 'mongoid' class Configuration
In PHP when we include or require some file using some initializers like the
I have these models: class Assignment(db.Model): title = db.StringPeoperty(required=True) ...other stuff... class TeamScore(db.Model): assignment
I read some other related questions and thought this was the best answer: set_include_path(get_include_path().PATH_SEPARATOR./path/to/program/root);
I have some models; Vocabularies (tags lists), Labels (tags) and different articles types. These
I have some models witch are using Doctrine nestedset feature. I want to add
How do I change some models name from Categorys to Categories on admin site
I have some models that are laid out like so (with a lot more
UPDATED: I am setting default scope for some models in a runtime which seems
Let's say I have some models: User , Post , and Vote . A

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.