Topic: autoload_paths change naming convention

Hi! This is my first post.

I have a problem with naming convention that Rails uses for loading the files of their config.autoload_paths.

I'm building an application that uses some set of gems.

This set of gems are supposed to be extended by the application in the way that, if a model User is defined inside the gem, then if the application wants to extend that model you will have to create a file named 'app/models/_user.rb', and inside that file you will write something like:

# Extending gems user model in the application level
class User < ActiveRecord::Base
  def new_method_that_make_sense_for_my_app
    #supercode here... bla bla

So, given that scenario, let's assume that this will not change. So, I will have to add this kind of files all over my app/models folder.
But while i'm developing, it would be nice that those extended models be reloaded in every request so if I make a change on the code there, i won't have to restart the server to apply those changes.
So, all of this suggests that I should add this file paths to my config.autoload_paths array in the application.rb.

Here's the problem:

For example, if I add the following code to my application.rb:

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

Rails won't autoload this file on each request, because the autoload_paths elements rely on the convention that the name of the file is equivalent to the name of the class defined in that file.

So, resuming: the underscore in "_user.rb" file name is messing everything up!

Is there a way to configure Rails so I can tell it to search also for files starting with an underscore and followed by the name of the class?


Last edited by marceloeloelo (2012-04-12 15:15:42)