I have a form in Rails where users can enter multiple records. I am going to write some JavaScript where users can have a virtually unlimited number of records. My hash is going to look like this:
inputA_1, inputB_1, inputC_1
inputA_2, inputB_2, inpuctC_2
In my controller I want to do a while loop to iterate through the rows and save them to the database, for example:
z = 0
i = 1
while z = 0
@inputA = [:params][:inputA_i]
@inputB = [:params][:inputB_i]
@inputC = [:params][:inputC_i]
if @inputA.nil?
z=1
else
@record = [inputA: @inputA, inputB: @inputB, inputC: @inputC]
@record.save
i = i + 1
end
end
The problem is that I don’t know how to make the “i” of :inputA_i be the value of i.
Any help in that would be appreciated.
Interpolate
iinto a string and convert string tosymbol: