我无法保存rails模型,它向我显示“ActiveRecord :: RecordNotSaved”。谢谢你。
m = Mentor.last
m.save
=> false
m.save!
ActiveRecord::RecordNotSaved
m.valid?
=> true
m.errors.any?
=> false
错误跟踪是:
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/persistence.rb:104:in `save!'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/validations.rb:56:in `save!'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/transactions.rb:246:in `block in save!'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/transactions.rb:208:in `transaction'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.2/lib/active_record/transactions.rb:246:in `save!'
from (irb):120
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
from /home/charizard/.rvm/gems/ruby-1.9.3-p429/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
答案 0 :(得分:4)
我发现了这些家伙。我使用MentorObserver进行了返回false的before_save回调。
如果任何回调返回false,则保存将不会继续进行并将引发&#34; ActiveRecord :: RecordNotSaved&#34;异常。强>
我通过使用git bisect工具找到了这个。一个很棒的工具。