views:

56

answers:

1

I want to reload a part of a form generated with the form_for-helper via AJAX. After reloading the part I still want to have access to the form object.

How can I do this?

Best regards

+1  A: 

I am not sure if your are using different terminology than I've heard, but what do you mean "still want to have access to the form object"?
Do you mean access to it in JavaScript? That should still work as long as you don't overwrite the form tags. Do you mean in the html.erb code generating the partial? That doesn't really make sense, because that form_for object has already generated its html tags and gone out of scope. You need to use to the regular form of the helpers that takes the name of the object as the first parameter. There is no problem with this working with the tags generated by the form_for version of the helpers.

So, in your main page:

<%= form_for :person, @person, :url => { :action => "create" } do |f| %>
    <%= f.text_field :name %>   
    <div id="reloadable">
    </div>
<% end %>

And in your partial that fills that div:

<%= text_field :person, :name %>

No step 3.

MattMcKnight