Can anyone tell me how to add routes from plugin? I know it is possible because of this changeset: http://dev.rubyonrails.org/changeset/2967 but i didn't find way how to do it. retro
on 2006-06-09 13:09
on 2006-06-09 18:30
Mihael Konjevic wrote: > Can anyone tell me how to add routes from plugin? I know it is possible > because of this changeset: http://dev.rubyonrails.org/changeset/2967 but > i didn't find way how to do it. > > retro Remember in Ruby, all clases remain open regardless of the file they are called from. So you should be able to simply mimic the structure of the routes.rb file. #vendor/plugin/foo/lib/foo.rb ActionController::Routing::Routes.draw do |map| map.my_route 'foo/:id', :controller => 'foo' end Never done it but it should work, in theory.
on 2006-06-09 19:07
Good guess but....No, it doesn't work. I'm looking for a way of doing this as well. I've been poking around in the routes code to work out whats going on as yet. It seems alot easier in edge rails. Can anyone shed any light on this? Cheers, Dan
on 2006-06-09 19:24
Just curious, did you apply the patch in that changeset?
on 2006-06-09 19:30
It's in Rails 1.1 already. It was applied 11/10/05.
on 2006-06-10 11:55
>From my own investigations earlier in the year, despite the fact that plugins are loaded before the routing is set up this doesn't allow the plugins to alter the routing in any trivial fashion i.e. outside of the block passed to Routes.draw. I have seen a plugin add routes by injecting some new functionality directly into the routing mechanism, but this requires a thorough understanding of the routing code, which is in turn hard to obtain since much of it is generated on the fly. Jamis Buck has been discussing a rewrite of this aspect of Rails on the core list recently. So, in a nutshell: it's possible (because nothing is impossible), but very very difficult.
on 2006-06-10 16:17
That sounds like a challenge! Right then of to the source we go. The annoying thing is that it's going to be two seperate solutions to the problem. One for 1.1 and one for the rewritten routes in edge rails (although the new routes are much easier to work with) I reckon I can do it though....
on 2006-06-10 21:21
Go Dan, go! ;-) -Ezra
on 2006-06-11 19:10
You can do it, put your hack into it. ahem. - james
on 2006-06-11 21:09
Ha ha, excellent pun action. Been looking at it this weekend and was thinking of a patch(or plugin or whatever) that allows a routes.rb to be specified in a plugin directory. When reload! is called it will load the plugin routes, then load the main routes...what do you all reckon? Is that a good approach?
on 2006-06-11 23:42
I think the key issue when you're considering routing with plugins (beyond actually making it work) is precidence. Because the plugin load order is currently at the whim and mercy of the filesystem, it may be problematic ensuring that the routes you define within plugin X aren't going to have a lower precidence that some which conincidentally match from plugin Y. I have in mind a patch to control plugin loading order because it's something I know that I would find useful, but even with this routing would still be a bit swampy - you'd have to inspect each plugin for potentially nasty routes and double-check the precidence yourself (hard enough when they're all in a single file, sometimes). That said, I'd still like it to be possible. When you're developing plugins/engines for internal use only, these kind of issues are more managable, and the benefits might outweigh the hassle. Dan - If you're at the LRUG meeting tomorrow, we can try and bash something out. - james
on 2006-06-12 01:02
Okay, yeah, I'll come along tomorrow. I know what you mean about precidence, it's a big problem. I've got a very specific use case for what I'm trying to do at the moment but to generalise it will be difficult. Anyway, speak to you tomorrow.