Rails partials should be explicitly called with locals

20 Mar 2007

Since Rails partials can see all the @variables of their parent view it’s pretty common to see partials with @’s all over the place. But the cool thing about partials is reusing them in other views and if you do you have to remember to populate all the stuff it needs and name everything the way it wants. Bah, I say. More and more I find myself explicitly calling partials with locals even if seems a bit redundant:

<%= render(:partial => ‘content/poll’,
:locals => {:poll => @poll}) %>

It goes along with this “partials are like methods” analogy I’ve been thinking about lately. And in big complicated pages with lots ‘o partials everything seems more clear. What do you think?