Update boolean and create new records simutaneously - Rails -


i need update boolean , create new records @ same time. have controller called bank, , bank has 3 attributes, namely account:string, amount:decimal , withdrawn:boolean, customer can invest amount specific number of days, after days reached can withdraw amount interest. need when customer clicks withdraw withdrawn boolean updated true, , amount+interest example amount+10% created , saved, amount+10% result have boolean/flag paid “bank teller” can change paid:, true after cash payment done.

how can achieve above, should create new controller , model withdrawal, , how code like? assistance appreciated.

no need create new controller. create withdraw method in controller. not sure mean amount+interest guess you're talking column in database. add amount_with_interest attribute in database. also, add column paid, boolean.

def withdraw the_bank = bank.find(params[:id]) #or similar account 1 way or  the_bank.withdrawn = true  the_bank.amount_with_interest = the_bank.amount * 1.1 the_bank.save end 

the teller can press other button somewhere after payment has been sent changes the_bank.paid true


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -