保存记录时的NoMethodError(未定义的方法`aasm_state')

时间:2016-10-05 15:59:23

标签: state-machine aasm

保存payment request时,会弹出错误:

NoMethodError (undefined method `aasm_state' for #<PaymentRequestx::PaymentRequest:0x007f574d229df8>):
  activemodel (4.2.0) lib/active_model/attribute_methods.rb:433:in `method_missing'
  aasm (4.11.0) lib/aasm/persistence/base.rb:36:in `aasm_read_state'
  aasm (4.11.0) lib/aasm/instance_base.rb:12:in `current_state'
  aasm (4.11.0) lib/aasm/persistence/active_record_persistence.rb:233:in `aasm_invalid_state?'
  aasm (4.11.0) lib/aasm/persistence/active_record_persistence.rb:225:in `block in aasm_validate_states'
  aasm (4.11.0) lib/aasm/persistence/active_record_persistence.rb:223:in `each'
  aasm (4.11.0) lib/aasm/persistence/active_record_persistence.rb:223:in `aasm_validate_states'
  activesupport (4.2.0) lib/active_support/callbacks.rb:427:in `block in make_lambda'
  activesupport (4.2.0) lib/active_support/callbacks.rb:189:in `call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:189:in `block in simple'
  activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_validate_callbacks'
  activemodel (4.2.0) lib/active_model/validations.rb:395:in `run_validations!'
  activemodel (4.2.0) lib/active_model/validations/callbacks.rb:113:in `block in run_validations!'
  activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
  activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
  activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_validation_callbacks'
  activemodel (4.2.0) lib/active_model/validations/callbacks.rb:113:in `run_validations!'
  activemodel (4.2.0) lib/active_model/validations.rb:334:in `valid?'
  activerecord (4.2.0) lib/active_record/validations.rb:58:in `valid?'
  activerecord (4.2.0) lib/active_record/validations.rb:83:in `perform_validations'
  activerecord (4.2.0) lib/active_record/validations.rb:37:in `save'
  activerecord (4.2.0) lib/active_record/attribute_methods/dirty.rb:21:in `save'
  activerecord (4.2.0) lib/active_record/transactions.rb:286:in `block (2 levels) in save'
  activerecord (4.2.0) lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
  activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
  activerecord (4.2.0) lib/active_record/transactions.rb:220:in `transaction'
  activerecord (4.2.0) lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
  activerecord (4.2.0) lib/active_record/transactions.rb:286:in `block in save'
  activerecord (4.2.0) lib/active_record/transactions.rb:301:in `rollback_active_record_state!'
  activerecord (4.2.0) lib/active_record/transactions.rb:285:in `save'
  /home/ubuntu/.rvm/gems/ruby-2.2.4/bundler/gems/payment_requestx-7836ca37b30f/app/controllers/payment_requestx/payment_requests_controller.rb:45:in `create'

保存在payment_requests_controller.rb

时发生错误
 if @payment_request.save

在此之前,成功节省了payment request。 gem AASM有什么问题?

1 个答案:

答案 0 :(得分:1)

Make sure you've added AASM要求迁移的列。