Forum: Ruby on Rails Thoughts about engines and 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.
3a83969376c805ef5b6042191fdb0ff3?d=identicon&s=25 Andreas S. (andreas)
on 2005-11-26 14:48
Hi,

at the moment it is quite difficult to combine multiple Rails apps, e.g.
a forum and a wiki. Neither components nor engines provide a sufficient
level of separation between the parts of the applications to make this
considerably easier, because in the end almost everything becomes mixed
up in the same namespace.

A way to avoid this would be to create all the engine classes (models,
controllers, helpers) inside a module. This would open a whole number of
interesting possibilities:

Controllers/Routing
===================

Controller names of different applications do not collide, you can have
a BooksController both in a wiki and in a book database.

To connect an URL directly to the controller of an engine:
  map.connect 'book/:id', :module = "wiki_engine", :controller =>
"books", :action => "show"

To delegate an URL to the routing of the engine:
  map.connect 'wiki/:url', :module = "wiki_engine"
...and the "url" part will be processed by the routes.rb of the engine.

Modules
=======

If you need to "talk" to a module of another engine you can write
  WikiEngine::Book.find(xyz)

If you want the WikiEngine and the BooksEngine to use the same "User"
model:
  WikiEngine::User = BooksEngine::User = MyUserModel

To prevent collision between table names you could assign a table prefix
to an engine or make it use a seperate database connection:
WikiEngine::table_prefix = 'wiki'


There might be problems I haven't thought of, and changing Rails to deal
with modules would probably be a lot of work. But on the other hand it
could be a more general solution for both components and engines in the
current form.

What do you think?

Andreas
37c332966b49eeb1d54eeefd3bc5ce97?d=identicon&s=25 dcorbin (Guest)
on 2005-11-26 15:05
(Received via mailing list)
On Saturday 26 November 2005 08:48 am, Andreas Schwarz wrote:
> Hi,
>
> at the moment it is quite difficult to combine multiple Rails apps, e.g.
> a forum and a wiki. Neither components nor engines provide a sufficient
> level of separation between the parts of the applications to make this
> considerably easier, because in the end almost everything becomes mixed
> up in the same namespace.

I haven't kept up with Rails for the last several months, but the last
time I
checked, it also had a problem in that it builds these humongous
$LOAD_PATHs.
This creates another problem in that your ruby filename as well as the
classes are all effectively in one user space.  Has anything been done
to
address this?

David
This topic is locked and can not be replied to.