# Prepend\_view\_path not working

**URL:** <https://www.ruby-forum.com/t/prepend-view-path-not-working/124039>\
**Category:** Rails\
**Created:** [December 23, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/prepend-view-path-not-working/124039 "2007-12-23T22:15:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cowboy\_x](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d78d45/32.png) [@cowboy\_x](https://www.ruby-forum.com/u/cowboy_x)\
**Post date:** [December 23, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/prepend-view-path-not-working/124039/1 "2007-12-23T22:15:02Z")

</div>

Now that controllers can have multiple view paths I’ve been playing with  
themes over the weekend. Running into a view issues. I have a  
before\_filter in the ApplicationController that calls prepend\_view\_path  
to add the path of my theme. I even log the view\_paths in an  
after\_filter to make sure it made it all the way through. The output  
looks something like:

/path/to/rails\_project/themes/default/views:/path/to/rails\_project/app/views

Yet nothing loads. In the docs it says calling prepend\_view\_path as an  
instance method will only effect the current request, which I figured  
should be fine. But I tried calling it as a class method as well, which  
is supposed to not effect the current request, but all future requests.  
Even this isn’t working as expected. Only way I’ve managed to get it to  
work is if I don’t ever clean it up. So I keep prepending over and  
over, making the path ridiculously long and redundant.

I even installed the [darwinweb.net](http://darwinweb.net) multisite plugin. Same issues. Only  
way I could get it to work is if I removed the code that cleaned up  
after itself, so the path got out of control.

Right now I’m running this with webrick locally on Leopard 10.5. Is  
this just a Leopard bug or am I maybe doing something wrong?

Here is what’s in my before\_filter:

prepend\_view\_path(RAILS\_ROOT + ‘/themes/default/views’)

Also tried:

ActionController::Base.prepend\_view\_path(RAILS\_ROOT +  
‘/themes/default/views’)

When printed to the log, the paths look great. Any suggestions?

---

<div class="post-metadata">

**Author:** ![cowboy\_x](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d78d45/32.png) [@cowboy\_x](https://www.ruby-forum.com/u/cowboy_x)\
**Post date:** [December 24, 2007, 2:22am UTC](https://www.ruby-forum.com/t/prepend-view-path-not-working/124039/2 "2007-12-24T02:22:24Z")

</div>

There’s a view\_paths accessor method. If you log view\_paths does that  
show your results as you expect them?

---

<div class="post-metadata">

**Author:** ![cowboy\_x](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d78d45/32.png) [@cowboy\_x](https://www.ruby-forum.com/u/cowboy_x)\
**Post date:** [December 24, 2007, 6:35am UTC](https://www.ruby-forum.com/t/prepend-view-path-not-working/124039/3 "2007-12-24T06:35:28Z")

</div>

Steve R. wrote:

> There’s a view\_paths accessor method. If you log view\_paths does that  
> show your results as you expect them?

Yes. I do think in the after\_filter to make sure it is there for the  
entire page render.

logger.info “soa paths: " + view\_paths.join(”:“)  
logger.info “soa paths: " + ActionController::Base.view\_paths.join(”:”)

Both of those output:

/path/to/rails\_project/themes/default/views:/path/to/rails\_project/app/views

Which is perfect. My themes directory comes up before the normal one.

---

<div class="post-metadata">

**Author:** ![cowboy\_x](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d78d45/32.png) [@cowboy\_x](https://www.ruby-forum.com/u/cowboy_x)\
**Post date:** [December 24, 2007, 7:37am UTC](https://www.ruby-forum.com/t/prepend-view-path-not-working/124039/4 "2007-12-24T07:37:26Z")

</div>

Well, it sounds like the code you should be looking at is in  
ActionView, and depending on how fresh your version of Rails is, I’d  
be looking in base.rb at the render\_file method. Whenever something  
like this stumps me, I use logger.debugs just like you are – if you  
want to go one more step, try ruby-debug and step through the render  
sequence to find out exactly how your template is being located.

Sorry not to be of much help here.

---

<div class="post-metadata">

**Author:** ![cowboy\_x](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d78d45/32.png) [@cowboy\_x](https://www.ruby-forum.com/u/cowboy_x)\
**Post date:** [December 25, 2007, 1:07am UTC](https://www.ruby-forum.com/t/prepend-view-path-not-working/124039/5 "2007-12-25T01:07:14Z")

</div>

After lots of debugging I found that the fix was incredibly simple and  
obvious. I was putting the code in a before\_filter block and for some  
reason that doesn’t work. Maybe scope issues. But if I put the prepend  
right after the class declaration, it works just fine. Even putting it  
in a function to be used by a before filter seems to work, as long as  
the function remains in the ActionController scope.

---

<div class="post-metadata">

**Author:** ![cowboy\_x](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d78d45/32.png) [@cowboy\_x](https://www.ruby-forum.com/u/cowboy_x)\
**Post date:** [December 24, 2007, 7:59am UTC](https://www.ruby-forum.com/t/prepend-view-path-not-working/124039/6 "2007-12-24T07:59:48Z")

</div>

Steve R. wrote:

> Well, it sounds like the code you should be looking at is in  
> ActionView, and depending on how fresh your version of Rails is, I’d  
> be looking in base.rb at the render\_file method. Whenever something  
> like this stumps me, I use logger.debugs just like you are – if you  
> want to go one more step, try ruby-debug and step through the render  
> sequence to find out exactly how your template is being located.
> 
> Sorry not to be of much help here.

Was running Rails 2.0.1, but upgraded to 2.0.2 to see if it fixed this.  
You gave me another direction to look, so I thank you for that. I  
generally don’t have to dig into Rails this deep, so I don’t know a lot  
of the internals as well as I would like.
