Problem using a controller inside a plugin

Mark,

I don't recall where I saw it, but there is a plugin out there that tweaks some of rails internals so that the plugins internal /public/ javascript and /public/images etc are checked. The idea is that instead of dumping everything into /lib in the plugin, your /app and / public directories are mirrored in the plugin as well!

I don't quite recall where I saw it, maybe on "Plugin A Day" site... I'll search around and see what I find...

Eric

I actually realized I need to do the same thing, introduce a controller in as part of a plugin.. Hollar if you find it first!

Yes, I was looking at it, and I shy away from plugins depending on plugins. At any rate, I'm in the same boat, so I'd love to hear the solution!

I hacked up a solution based on how ajaxscaffoldp does things. I just on startup copy the controller and other shared resources into my app. If I want to extend a controller/resource, then I think I would put that into antoher class so it wouldn't get overritten. Think of it as "auto generation"....

puts "Initiallizing boozer" # copy all the files over to the main rails app, want to avoid .svn source = File.join(directory,'/app/views/sessions') dest = File.join(RAILS_ROOT, '/app/views/sessions') FileUtils.mkdir(dest) unless File.exist?(dest) FileUtils.cp_r(Dir.glob(source+'/*.*'), dest)

source = File.join(directory,'/app/controllers') dest = RAILS_ROOT + '/app/controllers' FileUtils.cp_r(Dir.glob(source+'/*.*'), dest)

Hi,

There must be a way to do this approach better, but I'm not sure what it is yet.   

And there are some solutions for that indeed.

If you want your controller to use the views only from the plugin, then it's pretty easy and you're lucky. You can set in your controller the variable "self.template_root" pointing to the path with the views. Rails will use that for searching the views for your controller, so everything is fine.

Problem with this approach comes when you want to display views either from the plugin or from the app directory (or the other way around).

Right now, by using the stable versions the only way i know to do that is by reopening a class and adding code of your own. It works, but it's a bit hackish... BUT... if you don't mind using edge, then you can take a look at this http://dev.rubyonrails.org/ticket/2754

That way you can have alternative paths for searching the views of any given controller. However, I'd say for the problem you wanted to solve the first solution of using template_root would do.

Regards,

Javier Ramírez