Search code examples
ruby-on-railsmodel-view-controllermodelscontrollers

Rails: Update loan amount with amount paid


I am pretty new to rails and I wrote a little app that keeps track of loans. There is a User model and a Loan model and I have it worked out to track who loaned who money, etc.

I am trying to write a new feature that would keep track of payment but I am unsure where I should put it. This feature would update the database value of loan amount with a new value. Would this feature be a part of the Loan class, would it be a new controller that can access the loans / users model?

My apologies if this question is overly vague, I can supply more info is necessary.


Solution

  • You can just create a method in the Loan model make_payment(amount) and reduce the amount from the total loan amount.

    I would advice you to maintain a log of payments in order to keep track of them later. Create a Payment model that belongs to the Loan model.