Link_to_function variable increment

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=%{


Phone number
}
html<< (fields_for :contact_phones do |ff|
ff.text_field :phone_number,:index=>num
end )
html<<link_to_function(“delete”, “$(‘phone#{num}’).remove()”)
html<<%{
}
end

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs