Forum: Ruby on Rails Models within Modules

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cfe5712f1460402a395cf92ab11d1377?d=identicon&s=25 John (Guest)
on 2006-01-29 03:38
I have models within a module file and access them from my controller
with Module::Model syntax, but only get unitialized const errors. I even
tried require 'mymodule', etc, no avail. The Prg

Google has ZERO help on this, and I can't believe more people haven't
run into this issue. What's the deal?

Frustrated,
John
8ce2e37477dda38d7804b0498a0c9ef1?d=identicon&s=25 Eric Schlavo (Guest)
on 2006-01-29 05:52
Keep putting this at the top until it gets an answer
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-01-29 21:05
(Received via mailing list)
On Jan 28, 2006, at 6:38 PM, John wrote:

>
> --
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

John-

	Here is what you have to do if you are running 1.0.0. Add this line
in side the environment.rb file here:

Rails::Initializer.run do |config|

   # Add support to use models in modules for namespaces.
   config.controller_paths << File.join(::RAILS_ROOT, 'app', 'models')
  #.....
end


	Its a little weird becuase you use controller_paths but it will let
you use Admin::Page < AR::Base for your models to have them
namespaced inside of modules.

	This is the same way that components are able to load their models
and stuff. There has been support recently added to use this by
default on edge rails but im not sure if its been checked into the
repo yet.

Cheers-

-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2006-01-29 21:05
(Received via mailing list)
> There has been support recently added to use this by
> default on edge rails but im not sure if its been checked into the
> repo yet.

http://dev.rubyonrails.org/changeset/3493

Added reusable reloading support through the inclusion of the
Relodable module that all subclasses of ActiveRecord?::Base,
ActiveRecord?::Observer, ActiveController?::Base, and
ActionMailer?::Base automatically gets [DHH]. Added auto-loading
support for classes in modules, so Conductor::Migration will look for
conductor/migration.rb and Conductor::Database::Settings will look for
conductor/database/settings.rb [Nicholas Seckar]. Refactored
extensions to module, class, and object in active support [DHH]

--
Rick Olson
http://techno-weenie.net
This topic is locked and can not be replied to.