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

javascript - Slick Slider width recalculation -

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

angular2 services - Angular 2 RC 4 Http post not firing -