ruby-on-railspartial-views

Can you get a Rails partial's name from within the partial?


Is there a variable that contains a partial's name accessible from within the partial?

render partial: 'foo'

In _foo.haml:

.name
  = partial_name # would output "foo" 

Solution

  • __FILE__ will give you the file name

    <% __FILE__.split("/").last.sub(/^_/, "") %>