# Placing models in /app/model/subfolder

**URL:** <https://www.ruby-forum.com/t/placing-models-in-app-model-subfolder/85931>\
**Category:** Rails\
**Created:** [February 17, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/placing-models-in-app-model-subfolder/85931 "2007-02-17T19:39:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [February 17, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/placing-models-in-app-model-subfolder/85931/1 "2007-02-17T19:39:59Z")

</div>

Hi,

I would like to add some models to a sub folder under /app/models/. It  
seems that these are not loaded automatically.

Do I need to specify this new sub folder path somewhere? I tried adding  
it to environment.rb, but no luck:

config.load\_paths += %W( {RAILS\_ROOT}/app/models/external )

Any help would be much appreciated.

Thanks,  
GiantCranes

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [February 17, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/placing-models-in-app-model-subfolder/85931/2 "2007-02-17T20:28:39Z")

</div>

Sure, add the following to the Rails::Initializer block in  
config/environment.rb:

config.load\_paths += Dir["#{RAILS\_ROOT}/app/models/\*/"]

Hope this helps,  
GiantCranes

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [February 17, 2007, 8:29pm UTC](https://www.ruby-forum.com/t/placing-models-in-app-model-subfolder/85931/3 "2007-02-17T20:29:14Z")

</div>

Giant C. wrote:

> Sure, add the following to the Rails::Initializer block in  
> config/environment.rb:
> 
> config.load\_paths += Dir["#{RAILS\_ROOT}/app/models/\*/"]
> 
> Hope this helps,  
> GiantCranes

Thanks.

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [February 20, 2007, 5:30am UTC](https://www.ruby-forum.com/t/placing-models-in-app-model-subfolder/85931/4 "2007-02-20T05:30:19Z")

</div>

Giant C. wrote:

> Giant C. wrote:
> 
> > Sure, add the following to the Rails::Initializer block in  
> > config/environment.rb:
> > 
> > config.load\_paths += Dir["#{RAILS\_ROOT}/app/models/\*/"]
> > 
> > Hope this helps,  
> > GiantCranes
> 
> Thanks.

Hi, I need to do the same thing, but only with my views. I tried:

config.load\_paths += Dir["#{RAILS\_ROOT}/app/views/users/\*/"]

but no luck. Do I have to do something different when defining the  
action in the controller? Ideally, I’d like to have something like:  
tld.tld/users/favorites/appetizers/(user\_id).

Is there something additional I need to do, or is it even possible?

Thanks!

Dave

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [February 20, 2007, 11:01pm UTC](https://www.ruby-forum.com/t/placing-models-in-app-model-subfolder/85931/5 "2007-02-20T23:01:12Z")

</div>

Dave,

If you want to group controllers you can do so like this

# /app/controllers/admin/users\_controller.rb

class Admin::UsersController \< ApplicationController  
end

# /app/controllers/admin/images\_controller.rb

class Admin::ImagesController \< ApplicationController  
end

Both those controllers are then prefixed by ‘admin’ (.com/admin/users  
and .com/admin/images) and look for their views inside of /app/views/  
admin.

However for what you’re wanting to do I would look into RESTful  
routes. In app/config/routes.rb you can map resources (controllers)  
like so:

map.resources :users, :path\_prefix =\> “admin” (available at .com/admin/  
users)

the path prefix can be as long as you want, and if you want to get  
really crazy you do things like this:

map.resources :users do |user|  
user.resources :images  
end

then you could have a url like .com/users/9/images/4

[peepcode.com](http://peepcode.com) have a screencast on RESTful Rails it’s well worth  
spending the $9 on it.

hope that helps!

- Alastair

On Feb 19, 8:30 pm, “Dave A.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
