Who is causing a partial to be rendered?

14 views
Skip to first unread message

Ralph Shnelvar

unread,
Jul 26, 2017, 11:58:58 PM7/26/17
to Ruby on Rails: Talk
Is the a convenient programatic way for a partial to know what view (controller?) is causing it to be rendered?

For debugging purposes I want the partial to render the name of the view causing the partial to be rendered..

Ralph

Greg Navis

unread,
Jul 27, 2017, 1:53:35 AM7/27/17
to rubyonra...@googlegroups.com
I think rack-mini-profiler should fit the bill. It shows the queries you executed and layouts you rendered.

Phil Edelbrock

unread,
Jul 27, 2017, 2:23:37 AM7/27/17
to rubyonra...@googlegroups.com
I've done stuff stuff like this to pass in, to say, a mailer view to know how it is being called. Some variation of that might work for you:

@mailer_name = caller_locations(1,1)[0].label

Hope that helps.


Phil

Ralph Shnelvar

unread,
Jul 27, 2017, 2:46:00 AM7/27/17
to Ruby on Rails: Talk
This is close to what I want, I think.

Where does the "@mailer_name = caller_locations(1,1)[0].label " go?  In a controller?  In a view?

What I really want is to not have to modify the source modules that are invoking the rendering but, instead, have the _header.html.erb source module dynamically say "I got invoked by root.html.erb".

Things get a bit more dicey, I think, if the sequence is
  root.html.erb
  appllication.html.erb     (authomagically invoked)
  root.html.erb

Thoughts?
Reply all
Reply to author
Forward
0 new messages