-2

我正在开发我的应用程序时,控制台突然出现了一个错误。

使用 Rails 控制台时,我无法创建或保存模型。这是我得到的错误:

rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:418: syntax error, unexpected '=', expecting ')'
              result = result = _callback_before_71

我恢复到以前在 git 中的提交,但它仍然无法正常工作......

完整的错误信息:

SyntaxError: /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:418: syntax error, unexpected '=', expecting ')'
              result = result = _callback_before_71
                      ^
/Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:423: syntax error, unexpected keyword_end, expecting ')'
/Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:426: syntax error, unexpected keyword_end, expecting ')'
/Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:427: syntax error, unexpected $end, expecting ')'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:400:in `class_eval'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:400:in `__run_callback'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activemodel-3.2.11/lib/active_model/validations.rb:228:in `run_validations!'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activemodel-3.2.11/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:403:in `_run__1438787982741389732__validation__2895348434256153547__callbacks'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activemodel-3.2.11/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activemodel-3.2.11/lib/active_model/validations.rb:195:in `valid?'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/validations.rb:69:in `valid?'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/validations.rb:77:in `perform_validations'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/validations.rb:50:in `save'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/attribute_methods/dirty.rb:22:in `save'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/transactions.rb:259:in `block (2 levels) in save'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in `transaction'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/transactions.rb:259:in `block in save'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/transactions.rb:270:in `rollback_active_record_state!'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/transactions.rb:258:in `save'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/persistence.rb:45:in `create'
    from (irb):3
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
    from /Users/justindomingue/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'1.9.3-p374
4

1 回答 1

0

今晚我遇到了同样的问题,所以我将猜测导致您问题的代码。我的假设是您未能保存的模型使用的是 has_secure_password 类方法。根据我的经验,当您尝试对临时“密码”字段执行预定义验证(validates_presence_of、validates_length_of 等)时,您会遇到上述错误。当我切换到类似于 urgetopunt 在此博客文章中使用的验证时,错误消失了。

希望这对您有所帮助。

于 2013-07-05T06:40:52.100 回答