# Using partials with form\_for

**URL:** <https://www.ruby-forum.com/t/using-partials-with-form-for/159611>\
**Category:** Rails\
**Created:** [February 6, 2009, 11:07am UTC](https://www.ruby-forum.com/t/using-partials-with-form-for/159611 "2009-02-06T11:07:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sahil\_D](https://www.ruby-forum.com/u/Sahil_D)\
**Post date:** [February 6, 2009, 11:07am UTC](https://www.ruby-forum.com/t/using-partials-with-form-for/159611/1 "2009-02-06T11:07:28Z")

</div>

hi all

i was wondering whether it is possible to use partials along with  
form\_for  
and form\_field. following code is not working. is there some error or  
this  
case is impossible…??

_#new.html.erb_

# Enter Details for new Partner:

\<% form\_for(@partner) do |f| %\>  
\<%= render :partial =\> ‘form’, :locals =\> {:partner =\> f} %\>

\<%= f.submit "Create" %\>

\<% end %\>

_#\_form.html.erb_

\<%= f.error\_messages %\>

\<%= f.label :organisations\_id, "Organisation Id" %\>  
 \<%= f.text\_field :organisations\_id %\>

\<%= f.label :branches\_id, "Branch Id" %\>  
 \<%= f.text\_field :branches\_id %\>

## regards

Sahil

---

<div class="post-metadata">

**Author:** ![Sahil\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sahil\_D](https://www.ruby-forum.com/u/Sahil_D)\
**Post date:** [February 6, 2009, 11:35am UTC](https://www.ruby-forum.com/t/using-partials-with-form-for/159611/2 "2009-02-06T11:35:41Z")

</div>

On 6 Feb 2009, at 10:06, Sahil D. wrote:

> hi all
> 
> i was wondering whether it is possible to use partials along with  
> form\_for and form\_field. following code is not working. is there  
> some error or this case is impossible…??

You need to pass the form builder object to the partial (eg via  
locals). You are passing it, but then you’re not using it, so if you  
change your partial to use partner.error\_messages etc… it should work.

Alternatively you could just do

\<%= render :partial =\> f%\>

Because f is a FormBuilder this will render the partial \_form and will  
set the local variable form to be the form builder (so you’ll need to  
use form.error\_messages etc…).

Fred

---

<div class="post-metadata">

**Author:** ![Sahil\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sahil\_D](https://www.ruby-forum.com/u/Sahil_D)\
**Post date:** [February 7, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/using-partials-with-form-for/159611/3 "2009-02-07T20:55:17Z")

</div>

On Feb 6, 3:35 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> use form.error\_messages etc…).  
> thanks for the help Frederick. i got it.  
> but how do i get the value entered in a partial form…?

like i have an ‘address’ partial that i am rendering in a ‘user’ view.  
then how do i retrieve the values entered in partial in the ‘user’  
controller?  
specifically which ‘param’ symbol?
