The ELC Community Blog
A knowledge exchange on Ruby on Rails and Agile Development
Patching Rails - Rendering form partials
by damian on January 16, 2008
Yesterday we got a patch committed to Rails. This new enhancement provides a nicer and more conventional way of rendering form fields as a partial.
Instead of writing this not-so-DRY call to ,
1 render
<% form_for(@client) do |f| %> <%= render :partial => 'form', :locals => {:f => f} %> <%= submit_tag 'Create' %> <% end %>
... we can do something cleaner, like this:
<% form_for(@client) do |f| %> <%= render :partial => f %> <%= submit_tag 'Create' %> <% end %>
Here, the rendered partial is and the local variable inside the partial is called 1 clients/_form
.
1 form
If we used a different form builder,
<% form_for(@client, :builder => LabellingFormBuilder) do |f| %> <%= render :partial => f %> <%= submit_tag 'Create' %> <% end %>
... the partial that gets rendered is and the local variable is called 1 clients/_labelling_form
.
1 labelling_form
There have been
other proposals, but in the end we agreed that the method is the one who knows about the different kinds of things that can be rendered as partials (take, for example, 1 render
).
1 render :partial => @clients
The patch also changes the docs and provides unit tests for the new behavior.
Timeline
- Setting up a Flash Media Server on EC2 (CentOS)
- AWS/S3 may cause rake task failed
- Refreshing Rails Generated Views
- Environment Scripts in merb
- Script Terminal with TermInit
- Patching Rails - Rendering form partials
- Open Social plugin progress report
- Notify me when it's done
- OpenSocial on Rails, finally 1.0
- Testing without the database
- acts_as_chattable: make web chatting easy
Comments