How to update the values for import functionality in Rails? -


i having import.rb file maps different headers , stores database through csv/xls upload. in there fields new fields building directly. example, name , website stored directly in companies table alt_email , alt_email2 stored in email table type customers. (number of records stored @ time). here company has_many emails.

this rb file:

def import   name = fetch_value(row, "customer name", :string)   website = fetch_value(row, "website", :string)   cust_alt_email = fetch_value(row, "customer alternate email1", :string)   cust_alt_email2 = fetch_value(row, "customer alternate email2", :string)   customer_name = fetch_value(row, "customer name", :string)   company = customer_name ? customer_name.strip.chomp.squeeze(" ") : ""   if company.present?     customer = company.new     customer.name = company     customer.website = website      if cust_alt_email.present?       customer.emails.build(email: cust_alt_email)     end     if cust_alt_email2.present?       customer.emails.build(email: cust_alt_email2)     end    else     customer = company.find_by_id(customer_name_to_id[company.downcase])     if customer       customer.name = company       customer.website = website     end       end     end 

insert values working fine. build create, how update values or replace current values old ones? please me.


Comments

Popular posts from this blog

ios - UITEXTFIELD InputView Uipicker not working in swift -

Hatching array of circles in AutoCAD using c# -