Classic problem, please see
http://github.com/ryanb/complex-form-examples/tree/master and this
http://sifent.com/blog/2009/05/28/rails-nested-forms-jquery/
Essentially, what you need to do is, use :child_index =>
''NEW_RECORD''
and on click replace NEW_RECORD by some unique number (time will be
most appropriate) using javascript.
Thanks,
Abhinav
--
अभिनव
http://twitter.com/abhinav
On Wed, Sep 9, 2009 at 3:49 PM, prabesh
shrestha<prabesh708-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> My view looks like this
> <%count=0%>
> <%=link_to_function("add another", nil, :id =>
"more_link") do |
> page|
> page.insert_html :bottom, ''phone_numbers'',
add_phone_field(count
> +=1)
> end
> %>
> add_phone_field is a helper method.I need to increment count on every
> click.But my code above does not do that.
> Once count gets the value 1 it remains one.
> How can I increase the value of count on every click.
>
>
> My helper method :
> def add_phone_field(num)
> html=%{<div id="phone#{num}">
> <label for="contact_phones_phone_number">Phone
number</label>
> }
> html<< (fields_for :contact_phones do |ff|
> ff.text_field :phone_number,:index=>num
> end )
> html<<link_to_function("delete",
"$(''phone#{num}'').remove()")
> html<<%{</div>}
> end
>
> >
>