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_partialandrender_partial_collectionnow take option hashes to simplify their argument list.render_partialis 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_assignsas "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 August 22nd, 2008 @ 01:52 AM
- → Milestone changed from 2.x to 2.2
- → State changed from new to wontfix
- → 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 August 22nd, 2008 @ 03:05 AM
Took some of your ideas and cleaned up a few others things. Gave you the cred though.
1129a24
-
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
Repository is at http://github.com/rails/rails
Check out the development master (Edge Rails):
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"..
