# Rendering partials that need a FormBuilder local

**URL:** <https://www.ruby-forum.com/t/rendering-partials-that-need-a-formbuilder-local/136211>\
**Category:** Rails\
**Created:** [April 29, 2008, 9:02pm UTC](https://www.ruby-forum.com/t/rendering-partials-that-need-a-formbuilder-local/136211 "2008-04-29T21:02:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 29, 2008, 9:02pm UTC](https://www.ruby-forum.com/t/rendering-partials-that-need-a-formbuilder-local/136211/1 "2008-04-29T21:02:16Z")

</div>

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:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)
