Placing models in /app/model/subfolder

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

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

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.

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

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 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.” [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs