Topic: Nested Forms, AJAX and Rails 3

I'm moving an app from Rails 2.3 to Rails 3.
I have a campaign that has many filters.
The filters have many different types, so they are STI.

I have a form for creating / updating the campaign that has the the filters as nested attributes, which works fine in 2.3.  You pick which type of filter to add, click a button and it puts the new attributes in the form.

The code, in a .js.erb file, looks like this:

<% p = '' %>
<% fields_for @object do |f| %>
  <% f.fields_for :filters, @filter, :child_index => params[:index].to_i do |fields| %>
    <% p = render(:partial => "marketing/filters/#{@filter.class.to_s.underscore}", :locals => { :filter_form => fields }) %>
  <% end %>
<% end %>

$('<%= params[:target] %>').append('<%= escape_javascript p %>');

@object is the campaign and @filter is a new (unsaved) filter of the appropriate type.

This also works in Rails 3, but I get deprecation warnings for line 3, since the f.fields_for should now be using <%=.

What's the proper way to refactor this?

Re: Nested Forms, AJAX and Rails 3

I fixed this by following the example here: https://github.com/alloy/complex-form-examples

It's not as dynamic, but it works.