I am having this same problem, but I need to do this with ajax.....
any ideas? I've been racking my brain on this for a few hours now and
am losing it,
> Hi erol,
>
> Try this :
>
> <% form_for(@master_model) do |f| %>
> <%= f.error_messages %>
>
> <%-fields_for('master_model[sub_model][]', SubModel.new) do |sm| -
> %>
> <%= sm.text_field :field1 %>
> <%= sm.text_field :field2 %>
> <%= sm.text_field :field3 %>
> <%- end -%>
I find way better results with
form_remote_for([@master_model, @sub_model])
in cases where I need several instances of sub model
I do something like this in the view
<% unless @master_model.sub_models.nil? %>
<%= render :partial => 'sub_model', :collection => @master_model.sub_models, :object => @master_model%>
<% end %>
<%= render :partial => ‘new_sub_model’, :object => [@master_model, @sub_model] %>
then the partials use
div_for(sub_model) so the controller can talk back ajax to each instance of the form
the new_sub_model partial sends to create,
then create via rjs, refreshes the list of sub_models and shows a new empty new_sub_model template
>
> <%-fields_for('master_model[sub_model][]', SubModel.new) do |sm| -
> %>
> <%= sm.text_field :field1 %>
> <%= sm.text_field :field2 %>
> <%= sm.text_field :field3 %>
> <%- end -%>
> <p>
> <%= f.submit "Create" %>
> </p>
> <% end %>
>
> then check params format (it should be ok), then replace "form_for"
> with "remote_form_for" and check params format,
> "master_model[sub_model]" should be wrong
>
>
>
> > > i just checked it again and it looks like a form_remote_for bug,
> > > because with a non ajax form_for params are well formed,
> > > can someone confirm it?
>
> > It's impossible to confirm with the little information you've given.
> > Care to elaborate?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en)
-~----------~----~----~----~------~----~------~--~---
-- Andres Paglayan
CTO, StoneSoup LLC Ph: 505 629-4344
Mb: 505 690-2871
FWD: 65-5587
Testi. Codi. Vinci.