Rendering partials that need a FormBuilder local

At times I use partials to render pieces of a form like this

<% form_for @foo do |f| %>

<%= render :partial => 'foo', :locals => { :f => f } %>
... <% end %>

def edit
@foo = …
respond_to do |format|
format.html
end
end

That works nicely, of course. However, I hit a snag when I want to use
that partial in an ajax request to update something inside the form.
There, I need to pass in something comparable to the FormBuilder (f)
passed into the partial from within the complete view.

I’ve worked around this by wrapping the partial into another one like so

_foo_update.html.erb

<% fields_for @foo do |f| %>
<%= render :partial => ‘foo’, :locals => { :f => f } %>
<% end %>

and then use

page.replace_html ‘foo’, :partial => ‘foo_update’

I don’t particularly like this as I often don’t use plain
form_for/fields_for. Rather, I parameterize them with custom
FormBuilders (for labelling, say) and I’d prefer to do that in only a
single place. At any rate, I’d like to get rid of the wrapper partial.

Any ideas?

Michael


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/