# Get the path within a template (as in Rails template, not view template)

**URL:** <https://www.ruby-forum.com/t/get-the-path-within-a-template-as-in-rails-template-not-view-template/184174>\
**Category:** Rails\
**Created:** [February 26, 2010, 4:26am UTC](https://www.ruby-forum.com/t/get-the-path-within-a-template-as-in-rails-template-not-view-template/184174 "2010-02-26T04:26:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [February 26, 2010, 4:26am UTC](https://www.ruby-forum.com/t/get-the-path-within-a-template-as-in-rails-template-not-view-template/184174/1 "2010-02-26T04:26:04Z")

</div>

Hi guys. In one of my Rails templates (the type of template that you  
pass to “rails -m template.rb”), I’m trying to determine the path of  
the template.

I’ve checked for instance variables from within the template, but only  
@root and @logger exist.

Is there a way for the template to determine its path, or at least  
which directory it’s located in?

Thanks!  
Nick

---

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [February 26, 2010, 5:36am UTC](https://www.ruby-forum.com/t/get-the-path-within-a-template-as-in-rails-template-not-view-template/184174/2 "2010-02-26T05:36:53Z")

</div>

> Is there a way for the template to determine its path, or at least  
> which directory it’s located in?

Can you use **FILE**? Or File.dirname( **FILE** ) if you just want the  
directory?

Best,  
Steve

---

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [February 26, 2010, 6:05am UTC](https://www.ruby-forum.com/t/get-the-path-within-a-template-as-in-rails-template-not-view-template/184174/3 "2010-02-26T06:05:33Z")

</div>

On Feb 25, 11:35 pm, Steve R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Is there a way for the template to determine its path, or at least  
> > which directory it’s located in?
> 
> Can you use **FILE**? Or File.dirname( **FILE** ) if you just want the  
> directory?

Unfortunately not. It seems the template is pushed through #eval.  
This:  
puts “file = [#{ **FILE**.inspect}]”  
outputs this:  
file = [“(eval)”]
