View Path and Plugins

I have a plugin. I want to include some baseline views for the app code
to "just use" -- meaning no need to copy files into /app, and no need to
specify a path in the controller.

Is that possible? If I *have* to add something to the controller, that's
fine. The more important need is to have files reside in the plugin
folder.

I've googled and played with various blog tips, but nothing is working
the way I am wanting. This is not a case of applying skins or themes. I
just want a set of default files to be available to the app.

The closest thing I found was this post, but it doesn't work.

http://weblog.rubyonrails.org/2007/2/4/new-feature-for-rails-2-0-multiple-controller-view-paths

The key piece that confuses me is the line
ActionController::Base.view_paths.unshift File.join(directory, 'views')
-- it's not clear where "directory" is being defined.

I tried this with no joy:

plugin_folder = "#{File.dirname(__FILE__)}"
ActionController::Base.view_paths.unshift File.join(plugin_folder,
'views')

I must be missing something, because the above blog post seems like this
should be fairly simple.

-- gw

Greg Willits wrote:

I have a plugin. I want to include some baseline views for the app code
to "just use" -- meaning no need to copy files into /app, and no need to
specify a path in the controller.

Is that possible? If I *have* to add something to the controller, that's
fine. The more important need is to have files reside in the plugin
folder.

ActiveScaffold does this. You might want to take a look at their
implementation. If I remember, view_path is involved.

Best,

I tried this with no joy:

plugin_folder = "#{File.dirname(__FILE__)}"
ActionController::Base.view_paths.unshift File.join(plugin_folder,
'views')

How are you trying to use the views in your apps ? If my memory is
correct, setting view_paths means that rails will look in there in
addition to app/views and so on.

However assuming you're in foo_controller, just as normally
render :partial => 'blah' means look for app/views/foo/_blah, adding
to the view_paths means rails will also look for my_plugin/views/foo/
_blah. Were you expecting it to find my_plugin/views/foo ?
I believe these days that if you plugin contains a folder called app,
itself containing a folder called views then that will be added to the
view paths automatically

Fred

Frederick Cheung wrote:

I believe these days that if you plugin contains a folder called app,
itself containing a folder called views then that will be added to the
view paths automatically

That worked. I went back and tried the unshift thing too, this time with
a path that mirrored /app/views/ and that worked. I'm not even sure now
exactly what else I could have been doing before, but the partials were
not being loaded. Must have been another factor.

At any rate, it works like I want now. Default partials w/in plugin
folder being found and rendered, and easily overridable by adding a
partial in a parallel /app/views folder. Schweet.

thx Fred

-- gw