I have a model called JunkData and a model called Lead. All the fields that JunkData has Lead has as well, including:
first_name
last_name
phone
address
city
state
zip_code
do_not_mail
Now when the index action of JunkData is invoked, I render all the fields in the index template. However, I have a subtab where all the same data is populated in a form of a new Lead object, and the user is able to change any of the data in the new Lead form.
What is the best way to copy a specific subset of attributes from one model to another that are identical? All I can think of is a loop:
for junk in @junkdata
lead = Lead.new
junk.attributes.each_pair do |name, value|
lead.send(name=, value) if lead.respond_to? name
end
end