#881 √ wontfix
Ryan Bates

Refactoring ActionView::Partials

Reported by Ryan Bates | August 22nd, 2008 @ 12:54 AM | in 2.2

I saw some potential refactorings for ActionView::Partials to remove some duplication and clean things up. Attached is a patch.

Here's an overview of what I did.

  • render_partial and render_partial_collection now take option hashes to simplify their argument list.
  • render_partial is the gateway to all partial rendering, this simplifies the Base render methods
  • split up rendering into multiple methods to handle the various object types: array, form, string, and other objects. These methods call each other to stay dry.
  • the counter is now internally stored in local_assigns as "collection_counter" to simplify rendering of collections. I'm not entirely happy with moving this logic into Renderable#compile, but I couldn't think of a cleaner solution.

Let me know what you think.

Comments and changes to this ticket

  • Joshua Peek

    Joshua Peek August 22nd, 2008 @ 01:52 AM

    • → State changed from “new” to “wontfix”
    • → Milestone changed from “2.x” to “2.2”
    • → Assigned user changed from “” to “Joshua Peek”

    I don't like

    • I'm against adding more private methods to the view context. It would be better to push that logic into RenderablePartial and break it up if possible.
    • The Renderable#compile! method should have no logic concerning partials. I'd override compile! in RenderablePartial to add extra behavior.
    • Why do you need to change the assertion in test_render_partial_collection_without_as?

    I do like

    • Moving useful logic (from ActionController) into ActionView.
    • The idea of cleaning up Partial logic in general ;)
  • Joshua Peek

    Joshua Peek August 22nd, 2008 @ 03:05 AM

    Took some of your ideas and cleaned up a few others things. Gave you the cred though.

    1129a24

  • Ryan Bates

    Ryan Bates August 22nd, 2008 @ 05:32 AM

    Cool, thanks for doing that.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Source available from github

The Git repository resides at http://github.com/rails

Check out the current development trunk (Edge Rails) with:

git clone git://github.com/rails/rails.git

Creating or reviewing a patch

See the contributor guide.

Creating a feature request

Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.

Creating a bug report

When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.

Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.

Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".

Shared Ticket Bins

People watching this ticket

Attachments