igmnlt
igmnlt

Reputation: 220

Print file path when rendering a partial in Rails Views

I manually add file paths to my partials so that it's easy for me to debug them. The code uses slim syntax:

In a partial

= print_partial_dir 'admin/modules/_menu-left.html.slim'

Application helper

def print_partial_dir(path) "<!-- #{path} -->".html_safe if Rails.env.development? end

Is there anyway so that when I render a partial in a view, I execute a filter or a hook so that the partial's file path is printed as a comment before the partial itself? Preferably, only do this when the rails environment is in development.

Upvotes: 0

Views: 332

Answers (1)

Mayank
Mayank

Reputation: 727

If you really want debugging be eased by getting partial rendering information you can use gem "xray-rails"

group :development do
  gem 'xray-rails'
end

Then bundle and delete your cached assets:

$ bundle && rm -rf tmp/cache/assets

Restart your app, visit it in your browser, and press cmd+shift+x (Mac) or ctrl+shift+x to reveal the overlay ( Documentation)

In this way you can debug all your partials when they are rendered.

Hope this Helps..

Upvotes: 1

Related Questions