** I tried to compress all the info the really make my question
completely clear... here''s hoping I succeeded **
I''m working on a contact management app ( well part of an app ) that
allows for
each contact to have multiple email address, websites etc etc.
The basic form is as follows... ( _form_fields.rhtml )
<% @email = email if defined? email %>
<!--[form: email address]-->
<%= error_messages_for ''email'' unless email.nil? %>
<%= hidden_field ''email'', ''id'', {
''index'' => ?????? } %></p>
<p><label for="email_label"
class="InputTitle">Label</label><br/>
<%= text_field ''email'', ''label'', {
''index'' => ?????, ''maxlength'' =>
''32'', ''size'' => ''32'' }
%></p>
<p><label for="email_address"
class="InputTitle">Email</label><br/>
<%= text_field ''email'', ''address'', {
''index'' => ?????, ''maxlength'' =>
''32'', ''size'' => ''32'' }
%></p>
<!--[eoform:email address]-->
it gets pulled in by ( _form.rhtml )
<a href="#" onclick="return Element.toggle(
''email_address'' );">[ x ]</a>
<b>Email Address Info</b>
<%= link_to_remote "Add New Email Address", :url => { :action
=>
''new_email_form'' }, :update => "email_address",
:position => ''bottom'' %>
<br/>
<div id="email_address" style="display:none">
<% for email in emails %>
<%= render_partial ''email_address/form_fields'', nil,
''email'' => email %>
<% end %>
</div>
which gets pulled into the entire form by
<%= render_partial ''email_address/form'', nil,
''emails'' => @contact.emails %>
in a higher form...
so the idea would be that the final email forms be a series of email fields
<input id="email_address" name="email[???][address]"
size="30"
type="text" />
<input id="email_address" name="email[????][address]"
size="30"
type="text" />
What I need is help with how I should give each ''index'' (
currently the ????? above )
a value...
On initial form creation where we are in the render_partial it would be easy
enough
to use email_counter but that doesnt work when returning the form from my
''new_email_form'' that gets called from the link_to_remote
I''m sure somehow who has more experience with AJAX ( this is my
beginning with it )
has a nice way of dealing with this... your help greatly appreciated...
In case it helps in understanding here is a bit of controller code:
def new_email_form
render :partial => ''email_address/form_fields'', :layout
=> false, :locals => { :email => EmailAddress.new() }
end
def create
@contact = Contact.new( @params[ :contact ] )
@params[ :email ].each do |key, email|
@contact.emails << EmailAddress.new( email ) unless ( email[
:address ] == '''' )
end
.. snip rest..
def update
@contact = Contact.find( @params[ :id ] )
begin
Contact.transaction do
@params[ :email ].each do |key, email|
if email[ :id ]
unless ( email[ :address ] == '''' )
raise "" unless @contact.emails.find( email[ :id ]
).update_attributes( email )
else
@contact.emails.delete( EmailAddress.find( email[ :id ] ) )
end
else
@contact.emails << EmailAddress.new( email ) unless ( email[
:address ] == '''' )
end
end
... snip rest ...
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails