views:

20

answers:

1

Let's say, I connected the route / to WelcomeController's index action.

Inside of the index.html.erb-Template I want to display the path of the template from Rails.root upwards, ie.

<h1> We are rendering: <%= how_do_i_do_this? %></h1>

to render to

<h1> We are rendering: app/views/presentation/index.html.erb</h1>  

In Rails 2 I could access template.path, but this doesn't work anymore

Any ideas?

A: 

Because of how template rendering works in Rails, you will now be able to use __FILE__ for this instead. This works for me:

<%= __FILE__.gsub(Rails.root.to_s, "") %>

There may be a better way to do this however, but I couldn't find it when I went looking.

Ryan Bigg
Yep, this does the job. However, it comes with the major drawback that you can't factor it into a helper method, since that would screw up the __FILE__ constant.
flitzwald