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
Comments
Post a Comment