Magne
Magne

Reputation: 17243

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.

Upvotes: 5

Views: 1904

Answers (2)

J Baker
J Baker

Reputation: 64

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!

Upvotes: 2

dax
dax

Reputation: 11017

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.

Upvotes: 2

Related Questions