'How to find where a view partial is used?

How do you go about easily finding out where a Rails view partial is used?

In what views, controllers etc.

This is handy when working on an app that someone else wrote. You don't necessarily know what views are using a particular partial, or where to find where the partial is used when navigating the app in the browser.

Currently, I am using the Sublime Text editor to project-wide search for the partial name "form" or "_form", or for "render ", but this gives an unnecessary amount of useless results.



Solution 1:[1]

There's no built-in solution, but I wrote a gem to try to solve this exact problem: https://github.com/Negotiatus/Partial-Finder

It's a rake task that will recurse through your project and attempt to create the full render chain (and routes!) for a given partial. Hope it helps!

Solution 2:[2]

You could try putting this caller inside the partial, and then running your test suite:

#haml

- p caller[x]

#erb

<%- p caller[x] %>

I used x because you'll have to play around with which index you're calling to get useful information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 J Baker
Solution 2 dax