Forum: Ruby on Rails Problem using a controller inside 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.
486bc2e99e507e271cb2b8eaa6501b60?d=identicon&s=25 Mark (Guest)
on 2007-02-22 20:13
Hi all,

I'm creating a plugin that has a controller (WebController <
ActionController::Base) inside its lib directory (lib/web_controller.rb)
so you can access your mini 'control-panel' via the web but I'm having
big problems rendering partials, images, js, etc because Rails is
looking by default to /public/images, /public/javascripts, etc...
instead of my plugin's dir.

The ideal situation would be to have all the plugin's
images/js/css/views inside my plugin so it doesn't 'disturb' your app's
file structure, but I have no idea how to do that.

Any help would be really appreciated.

Thanks a lot.
9cd154bd87385c597d95250177e5bca6?d=identicon&s=25 Eric Pugh (Guest)
on 2007-02-22 20:26
(Received via mailing list)
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
486bc2e99e507e271cb2b8eaa6501b60?d=identicon&s=25 Mark (Guest)
on 2007-02-22 20:47
Eric,

Thanks a lot for the tip. I found it on "Plugin a Week" and it seems
pretty interesting, that may be a good place to start.

Mark



Eric Pugh wrote:
> 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
9cd154bd87385c597d95250177e5bca6?d=identicon&s=25 Eric Pugh (Guest)
on 2007-02-22 21:32
(Received via mailing list)
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!
486bc2e99e507e271cb2b8eaa6501b60?d=identicon&s=25 Mark (Guest)
on 2007-02-22 21:44
I found it here http://wiki.pluginaweek.org/Appable_plugins , it seems
pretty interesting but I think his solution is too much for what I need.
I'll try to tweak it around to my needs and see if works.


Eric Pugh wrote:
> 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!
9cd154bd87385c597d95250177e5bca6?d=identicon&s=25 Eric Pugh (Guest)
on 2007-02-22 21:57
(Received via mailing list)
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!
9cd154bd87385c597d95250177e5bca6?d=identicon&s=25 Eric Pugh (Guest)
on 2007-02-22 22:55
(Received via mailing list)
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)
486bc2e99e507e271cb2b8eaa6501b60?d=identicon&s=25 Mark (Guest)
on 2007-02-22 23:18
Yeah I guess I could do that as well, but I'd prefer having it all
inside my plugin's directory specially because I'm planning on releasing
it to the public, and personally, I wouldn't be happy if I installed a
plugin that copied a bunch of files over to my main app.

There must be a way to do this approach better, but I'm not sure what it
is yet. I'd be great if DHH could give us a hint on that.



Eric Pugh wrote:
> 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)
1f2eadfb41362800ebc2cf211b91d0f7?d=identicon&s=25 javier ramirez (Guest)
on 2007-02-23 03:23
(Received via mailing list)
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

--------
Estamos de estreno... si necesitas llevar el control de tus gastos
visita http://www.gastosgem.com !!Es gratis!!
486bc2e99e507e271cb2b8eaa6501b60?d=identicon&s=25 Mark (Guest)
on 2007-02-23 19:59
Javier,

Thanks a lot. By defining and setting the template_root inside my
controller I was able to access the views/helpers within my plugin just
fine.



javier ramirez wrote:
> 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
>
> --------
> Estamos de estreno... si necesitas llevar el control de tus gastos
> visita http://www.gastosgem.com !!Es gratis!!
This topic is locked and can not be replied to.