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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:19:47+00:00 2026-06-18T11:19:47+00:00

I implemented STI in one of my models, using some tips from Alex Reisner’s

  • 0

I implemented STI in one of my models, using some tips from Alex Reisner’s blog post. I already had all my subclasses use the superclass’s controller, with serialize/store to hold the extra attributes. I added the model_name and self.select_options methods to the superclass, and the preload initializer from Alex’s blog. I also changed my collection_select in the _form view helper and attribute validation to use the self.select_options method. All my subclasses are in individual files in a app/models/subfolder, though they’re not namespaced like SubFolder::Subclass.

Then I start running into problems. Upon changing any code, self.select_options stops returning all of the subclasses. It only returns a small subset or none. Thus due to the validation and _form tie-in, I can’t edit/update my models after a code change. From what I could tell, when I change any code, Rails reloads the environment, but not the models in the subfolder.

I tried adding the routes to config.autoload_paths like many suggest, but ultimately that didn’t work.

So ultimately, I want:

  • Something to fix the autoloading, so I won’t have to restart the server after every change
  • Base it off the subdirectory containing all the children, to avoid manually maintaining an array
  • Rails 3.2.11, ruby 1.9.3p125, ubuntu 12.04.01, rvm
  • 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-18T11:19:48+00:00Added an answer on June 18, 2026 at 11:19 am

    I ended up combining the code from this answer and this one and knowledge gleaned from the wondible blog posts at the bottom. The config.autoload_paths never seemed to help anything, but I kept them in there. The key part is the initializer that requires all the files in the subdirectory on startup and then at each reload. I tried load over require_dependency, which didn’t work. It’s definitely been nice not having to reload all the time.

    In application.rb

    config.autoload_paths += %W(#{config.root}/app/models/configuration)
    

    In development.rb

    config.autoload_paths += Dir["#{config.root}/app/models/configuration/**"]
    

    In preload_sti_models.rb

    if Rails.env.development?
      Dir.entries("#{Rails.root}/app/models/subfolder").each do |c|
        require_dependency File.join("app","models", "subfolder", "#{c}") if c =~ /.rb$/
      end
      ActionDispatch::Reloader.to_prepare do
        Dir.entries("#{Rails.root}/app/models/subfolder").each do |c|
          require_dependency File.join("app","models", "subfolder", "#{c}") if c =~ /.rb$/
        end
      end
    end
    

    Some blog posts with useful information

    1. http://wondible.com/2012/01/13/rails-3-2-autoloading-in-theory/
    2. http://wondible.com/2011/12/30/rails-autoloading-cleaning-up-the-mess/
    3. http://wondible.com/2011/12/23/give-rails-autoloading-a-boot-to-the-head/
    4. http://www.williambharding.com/blog/technology/rails-3-autoload-modules-and-classes-in-production/

    Edit: it’s a known thing.

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

Sidebar

Related Questions

I implemented some code using backbone.js in Asp.NEt MVC3 and found backbone.js very helpful.
I implemented a (simple) python generator. Now, I want to make another one (from
I implemented one custom workflow in in Visual Studio 2010 using CRM 2011 Developer
I implemented the Add Friend dialog on iPhone using the post on stackoverflow: Facebook
Implemented some barbuttons by using below code, UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems: [NSArray
Implemented a generic repository with several Methods. One of those is this: public IEnumerable<T>
We implemented In-app Billing one year ago with no problems following the sample code
I implemented a Section List View following instruction from https://nodeload.github.com/necronet/section-list/zip/master . Everything working fine,
I implemented Gaussian recursive filter(by R. Deriche) using OpenCV and c++. However, the result
I implemented the facebook share button in my page using javascript, like this: <script

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.