Rails: How to dynamically add rows to database through controller method? -


after accepting data through form 1 table, want process data , use generate entries table. taking first set of data, plugging formula, , entering result entry of table. each original set of data generates multiple rows in other table (as formula runs several times 1 variable being incremented throughout runs).

in short, want this:

def show   @diagram = diagram.find(params[:id])   @horizon = @diagram.horiz    @horizon.times |i|     @cashflow = cashflow.new     @flow = compute_cashflow(@diagram.investment, i)     @cashflow.flow = @flow     @cashflow.year =     @cashflow.save   end end 

is possible? in advance.

edit here function "compute_cashflow(investment, year)":

def compute_cashflow(investment, year)   return investment+year end 

(it's meaningless right want test idea) enter image description here


Comments

Popular posts from this blog

java - unable show chart in xls document using jasper reports -

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -