Dynamically adding routes from your engine plugins
At Cohesive FT I am developing a sort of webmin console that has drop-in pluggable components. I am using the RoR plugin system with the engines plugin to drop entire chunks of MVC infrastructure into my application as required. This is all well and good except that rails engines require you to add this line into your routes.rb:
map.from_plugin :your_plugin_name
Now since I want a truly plug-n-play system, I can’t be modifying the route file of my main application. So here is a quick solution to import all the routes (note that in engine-plugin style you do not use the “map.” prefix for your routes, so I am adding that in)
#--routes.rb of the main applicatoin--
Dir["#{RAILS_ROOT}/vendor/plugins/*"].each do |plugin|
File.open(”#{plugin}/routes.rb”).each do |line|
eval “map.#{line}”
end
end
That’s all folks!










3 Comments