Custom form builder methods won't render in partial

Methods of custom form builder work if the form is in a view, but doesn't work if the form is in a partial.

My rediced code example looks like this:

# -- Builder ----------------------------------------- class CustomBuilder < ActionView::Helpers::FormBuilder

def drawTextField    return '<input type="text" />' end

# -- View -------------------------------------------- <% form_for :thisUser,    :url => {:action => :testForm},    :builder => CustomBuilder do |form| %>

   <%= render(:partial => 'testForm'}) rescue nil %>

<% end %>

# -- Partial ----------------------------------------- <%= form.drawTextField %>

If I simply move the drawTextField line into the view it works fine. Using the partial, the page renders everything but the partial (no field). No errors in log.

I poked around a fair bit, but have no more ideas to try.

-- gw (www.railsdev.ws)

Nevermind. I'm an idiot. Obviously the |form| object has to be passed into the partial. Duh.

-- gw (www.railsdev.ws)

Greg, I don't mean to muddy the waters on this question, but I believe that you need to have a

<%= render :partial => "form", :locals => { :form => form } %>

type statement to pass the 'form' value from the calling view to the partial. Kathy

I don't think so. Your formbuilder methods will be available to
partials just as if they were any view. I use a custom formbuilder in
almost all my forms and I use a lot of partials due to heavy reliance
on rjs. Greg, I didn't see the original stacktrace you sent. Can you
paste it back in?

-Bill

@Kathy

<%= render :partial => "form", :locals => { :form => form } %>

Yeah, that's what I did to solve it.

@Bill

Your formbuilder methods will be available to partials just as if they were any view"

Hmm, well, there's a definite correlation to it working or not if I pass the the form builder into the partial.

I didn't see the original stacktrace you sent. Can you paste it back in?

Below is the original reduced code I tested. The update now is that if I add a :locals to the render command to pass the form variable thru, it works.

-- gw (www.railsdev.ws)

Why did you think "form" would be in scope in the partial? The way I
always handle this is as follows:

<% form_for :foo do |f| %>    <%= render :partial => 'bar', :locals => {:f => f} %> <% end %>

Then in the partial, using any member of the yielded object "f" is
valid.

Does this help?