Forum: Ruby on Rails Adding routes via a plugin...

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.
5ce55767684e0cd1727db2b8b8975640?d=identicon&s=25 Steve Longdo (Guest)
on 2006-02-08 18:11
(Received via mailing list)
I have a plugin that I am working on that will as part of its
distribution
contain a controller.  I would like to be able to add a route for it in
the
plugin's init.rb so that when the plugin is loaded, the route will
automatically be registered without having to force the user to edit
routes.rb or even make a rake task to do it for them.

I saw the following code in one of the SVN rails/plugin modules:

ActionController::Routing::RouteSet.send :include, RestfulRoutes

, but it just includes a module with a method to add named routes.

I would like to actually add a route to the routeset automatically.  I
tried
using variations on the above to directly call named_route from my
plugin's
init.rb, but I have not been able to get it to work.

Also I notice that there is a reload method in the routing.rb file that
will
clear out the current named routes and read in the routes.rb file again.
Does this get called internally somewhere by Rails?  I guess I am
wondering
that even if I figure out a way to add my route dynamically, Rails might
call the reload method after my plugin is loaded and my route woud go
away
anyway.

Should I just pursue a rake task as part of the install to add the route
into the routes.rb file, or can what I want to do be accomplished with
Rails
1.0?

Thanks,
-Steve
http://www.stevelongdo.com
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-02-08 18:24
Steve Longdo wrote:
> I have a plugin that I am working on that will as part of its
> distribution
> contain a controller.  I would like to be able to add a route for it in
> the
> plugin's init.rb so that when the plugin is loaded, the route will
> automatically be registered without having to force the user to edit
> routes.rb or even make a rake task to do it for them.

How would you know if your route will break other routes?
Should it be first in the list or last?
Does it conflict with existing routes?

These seem like good reasons to make users define one manually.

_Kevin
5ce55767684e0cd1727db2b8b8975640?d=identicon&s=25 Steve Longdo (Guest)
on 2006-02-08 19:53
(Received via mailing list)
Ideally I would be using a namespace to prevent just that.  Similiar to
the
Recommendation to not use the ActiveRecord::Acts namespace for
developing
plugins, I placed my module extensions in a Longdo::Acts namespace.
Also
named routes are designed to overcome this very problem.  That said I
still
would probably use 'longdo/:controller/:id/:value' to prevent conflicts.
Similar in a sense to Java packages.

That said, I am more interested in the technical feasability of dynamic
routing versus simple namespace issues.  Any other thoughts?
This topic is locked and can not be replied to.