Last active
December 16, 2015 19:30
-
-
Save telagraphic/5485880 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActiveRecord::RecordInvalid in PaymentsController#create | |
| Validation failed: Amount is not a number | |
| Rails.root: /Users/telagraphic/Documents/programming/rails_projects/life-ulator | |
| Application Trace | Framework Trace | Full Trace | |
| app/controllers/payments_controller.rb:8:in `block in create' | |
| app/controllers/payments_controller.rb:7:in `create' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Payment < ActiveRecord::Base | |
| attr_accessible :amount | |
| validates :amount, presence: true, :numericality => true | |
| belongs_to :debt | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create | |
| @debt = Debt.find params[:debt_id] | |
| @payment = @debt.payments.build params[:payment] | |
| @payment.user_id = current_user.id | |
| @payment.transaction do | |
| if @payment.save | |
| @debt.update_attributes(amount: @debt.amount - @payment.amount) | |
| redirect_to @debt | |
| else | |
| render @debt | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment