can't convert String into Integer error on updating

<% form_for (:contact,:url=>{:controller=>'contact',:action => 'update',:id => @contact},:html=> {:onSubmit => 'return validate()', :id => 'savecontact'} ) do -%> . . . . <table cellpadding="4" cellspacing="0" border="1" width="100%" class="details"> <tr> <th colspan="4" align="left" bgcolor="#797ba8"><strong><font color="fffff">Email Addresses</font></strong></th> </tr> <tr>    <% for email in @contact.emails %>    <% fields_for "contact[email_attributes]", email do |e| %>    <td nowrap class="formLabel">Email </td>    <td > <%= e.select ('email_type',%w{Business Personal}, :include_blank => false) %>    <%= e.text_field :email,:size=>"35",:maxlength=>"80" %>    <%= e.radio_button ('isprimary', '1') %>Primary    </td> </tr> <% end %> <% end %></table> . . is my view page and here is my update function in contact_cotroller.rb

def update @contact = Contact.find(params[:id])        if @contact.update_attributes!(params[:contact])         flash[:notice] = "The contact has been updated successfully."            redirect_to :action => 'view', :id => @contact         else             render :action => 'edit'         end end is throwing the following error can't convert String into Integer

RAILS_ROOT: E:/ruby1/Ruby/BCMS Application Trace | Framework Trace | Full Trace

app/models/contact.rb:11:in `' app/models/contact.rb:11:in `email_attributes=' app/models/contact.rb:10:in `each' app/models/contact.rb:10:in `email_attributes=' app/controllers/contact_controller.rb:59:in `update

Where am i going wrong..??

and my contact.rb is class Contact < ActiveRecord::Base belongs_to :company, :counter_cache => false has_many :users has_many :addresses has_many :emails has_many :phones validates_presence_of :namefirst, :namelast,:message=>'Database Validation Error from Contact'

def email_attributes=(email_attributes)   email_attributes.each do |attributes|     emails.build(attributes) unless attributes["email"].empty?   end end

plz help

Hi, Just a guess...

<% form_for (:contact,:url=>{:controller=>'contact',:action => 'update',:id => @contact},:html=> {:onSubmit => 'return validate()', :id => 'savecontact'} ) do -%> . . . . <table cellpadding="4" cellspacing="0" border="1" width="100%" class="details"> <tr> <th colspan="4" align="left" bgcolor="#797ba8"><strong><font color="fffff">Email Addresses</font></strong></th> </tr> <tr> <% for email in @contact.emails %> <% fields_for "contact[email_attributes]", email do |e| %>

So this will generate   params[:contact][:email_attributes][<email_id>][<email_field>] => <field value in form> Each element in this params is a hash. Check your server logs to verify that that is what you're getting.

<td nowrap class="formLabel">Email </td> <td > <%= e.select ('email_type',%w{Business Personal}, :include_blank => false) %> <%= e.text_field :email,:size=>"35",:maxlength=>"80" %> <%= e.radio_button ('isprimary', '1') %>Primary </td> </tr> <% end %> <% end %></table> . . is my view page and here is my update function in contact_cotroller.rb

def update @contact = Contact.find(params[:id]) if @contact.update_attributes!(params[:contact]) flash[:notice] = "The contact has been updated successfully." redirect_to :action => 'view', :id => @contact else render :action => 'edit' end end is throwing the following error can't convert String into Integer

RAILS_ROOT: E:/ruby1/Ruby/BCMS Application Trace | Framework Trace | Full Trace

app/models/contact.rb:11:in `' app/models/contact.rb:11:in `email_attributes=' app/models/contact.rb:10:in `each' app/models/contact.rb:10:in `email_attributes=' app/controllers/contact_controller.rb:59:in `update

Where am i going wrong..??

and my contact.rb is class Contact < ActiveRecord::Base belongs_to :company, :counter_cache => false has_many :users has_many :addresses has_many :emails has_many :phones validates_presence_of :namefirst, :namelast,:message=>'Database Validation Error from Contact'

def email_attributes=(email_attributes) email_attributes.each do |attributes|

email_attributes is a hash with keys being email id's pointing to email attributes. See previous note above. When you do email_attributes.each |attributes| , 'attributes' will be an array with the first value being the key and the 2nd element being the value.

emails\.build\(attributes\) unless attributes\[&quot;email&quot;\]\.empty?

Calling attributes["email"] would trigger the above conversion error because arrays expect numeric indexes.

end end

Also, I noticed you're saying ":id => @contact" . I would have though @contact.id but might be missing something.