Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Last active December 16, 2015 19:30
Show Gist options
  • Save telagraphic/5485880 to your computer and use it in GitHub Desktop.
Save telagraphic/5485880 to your computer and use it in GitHub Desktop.
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'
class Payment < ActiveRecord::Base
attr_accessible :amount
validates :amount, presence: true, :numericality => true
belongs_to :debt
end
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