# View Path and Plugins

**URL:** <https://www.ruby-forum.com/t/view-path-and-plugins/191171>\
**Category:** Rails\
**Created:** [July 6, 2010, 11:49pm UTC](https://www.ruby-forum.com/t/view-path-and-plugins/191171 "2010-07-06T23:49:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [July 6, 2010, 11:49pm UTC](https://www.ruby-forum.com/t/view-path-and-plugins/191171/1 "2010-07-06T23:49:36Z")

</div>

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.

> **[New Feature for Rails 2.0: Multiple Controller View Paths](https://rubyonrails.org/2007/2/4/new-feature-for-rails-2-0-multiple-controller-view-paths)**
>
> 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...

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

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [July 7, 2010, 12:34am UTC](https://www.ruby-forum.com/t/view-path-and-plugins/191171/2 "2010-07-07T00:34:58Z")

</div>

Greg W. 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,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [July 8, 2010, 7:12pm UTC](https://www.ruby-forum.com/t/view-path-and-plugins/191171/3 "2010-07-08T19:12:19Z")

</div>

On Jul 6, 10:49 pm, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [July 9, 2010, 6:01am UTC](https://www.ruby-forum.com/t/view-path-and-plugins/191171/4 "2010-07-09T06:01:23Z")

</div>

Frederick C. 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
