# Form helpers and partial

**URL:** <https://www.ruby-forum.com/t/form-helpers-and-partial/175563>\
**Category:** Rails\
**Created:** [September 15, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/form-helpers-and-partial/175563 "2009-09-15T17:22:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [September 15, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/form-helpers-and-partial/175563/1 "2009-09-15T17:22:55Z")

</div>

Hi,

I’m trying to use a partial in my form (Rails 2.3.4), and the docs I see  
say I can do this:

edit.html.erb:  
\<% form\_for(@course) do |f| %\>  
\<%= render :partial =\> f %\>

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

\<% end %\>

\_form.html.erb:

Title: \<%= f.text\_field :title %\>

But when I go to the edit page I get an error:

undefined local variable or method `f’ for #ActionView::Base:0x465873c

If I change the render line to be:  
\<%= render :partial =\> “form”, :locals =\> {:f =\> f} %\>

it works, but the latest updates say I don’t need to do that.

Am I missing something?

Thanks.

---

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [September 15, 2009, 5:30pm UTC](https://www.ruby-forum.com/t/form-helpers-and-partial/175563/2 "2009-09-15T17:30:02Z")

</div>

John T. wrote:

> Hi,
> 
> I’m trying to use a partial in my form (Rails 2.3.4), and the docs I see  
> say I can do this:
> 
> edit.html.erb:  
> \<% form\_for(@course) do |f| %\>  
> \<%= render :partial =\> f %\>
> 
> \<%= f.submit "Update" %\>
> 
> \<% end %\>
> 
> \_form.html.erb:
> 
> Title: \<%= f.text\_field :title %\>

Well, slight update. I found that if I change my form partial to be:

\<%= form.text\_field :title %\>

it works. I can live with that.

But… reading the updates to rails and forms and partials, it says you  
can shortcut it more by doing:  
\<%= render @course %\>

I found that Rails will look for the partial named: \_course.html.erb.  
Ok, I copied my form partial, but it doesn’t like any of my ‘form  
helper’ variables - f.text\_field, form.text\_field, or course.text\_field.  
Is this possible?

thanks again

---

<div class="post-metadata">

**Author:** ![johnt519](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/cab0a1/32.png) [@johnt519](https://www.ruby-forum.com/u/johnt519)\
**Post date:** [September 15, 2009, 5:53pm UTC](https://www.ruby-forum.com/t/form-helpers-and-partial/175563/3 "2009-09-15T17:53:39Z")

</div>

On Sep 15, 4:30 pm, “John T.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Well, slight update. I found that if I change my form partial to be:
> 
> \<%= form.text\_field :title %\>
> 
> it works. I can live with that.

Correct. The magical partial variable has the same name as the partial  
itself

> But… reading the updates to rails and forms and partials, it says you  
> can shortcut it more by doing:  
> \<%= render @course %\>
> 
> I found that Rails will look for the partial named: \_course.html.erb.  
> Ok, I copied my form partial, but it doesn’t like any of my ‘form  
> helper’ variables - f.text\_field, form.text\_field, or course.text\_field.  
> Is this possible?

You would need to pass (via locals etc.) the form builder object.

Fred
