New Feature for Rails 2.0: Multiple Controller View Paths
Posted by rick February 04, 2007 @ 11:12 PM
Thanks to John Long, Rails now supports multiple view paths for each controller. For 90% of the apps, this probably won’t make a huge difference. But, for those of you wanting to productize various open source apps, you can now do this:
/beast/trunk$ mkdir vendor/plugins/test_view_paths
/beast/trunk$ cd vendor/plugins/test_view_paths
/beast/trunk/vendor/plugins/test_view_paths$ mkdir views
/beast/trunk/vendor/plugins/test_view_paths$ echo "ActionController::Base.view_paths.unshift File.join(directory, 'views')" > init.rb
What you’ve done is created a minimal rails plugin that inserts a ‘views’ directory in the plugin to the beginning of the #view_paths array. Now, copy a view from the rails app into the plugin’s ‘views’ directory, make a noticeable change, and start your app. You’ll notice that it picked your plugin’s view over the application’s view.

cool. first words about rails 2.0 :D~
Well, anything in Edge now that’s not in 1.2 is a Rails 2.0 feature.
I strongly feel that plugin views should be in vendor/plugins//app/views and not in vendor/plugins//views. Doing this would follow the same conventions a standard rails app has and will pave the way for putting controllers, helpers and models in plugins as well.
Silly asterisk to bold conversion… what I meant to say was:
... should be in vendor/plugins/PLUGIN/app/views and not in vendor/plugins/PLUGIN/views…
It’s a plugin, do whatever you want. I was going for a simple example.
I have worked with John on getting out the 0.6 release of RadiantCMS, which includes this enhancement (as part of Radiant, not a modified version of Rails). Hopefully next up will be multiple fixture paths!
Multiple migration paths would be great to!
FInally! I can abandon my forked version of Collaboa! Thank you so much.
Awesome
Will this be available as a plugin to start using right away?
There are already a couple of plugin implementations that supply this functionality – the engines plugin (new “cast any preconceptions aside” release, as of yesterday), and “plugin_routing” from pluginaweek.org, for example.
10 yep. pretty much an engine feature.