Rails3 ActiveRecord对多个操作进行after_commit事务

时间:2013-09-03 23:37:40

标签: ruby-on-rails ruby activerecord

根据the documentation,我可以定义在提交创建或更新类型后执行的相同方法:

after_commit :do_foo_bar, :on [:create, :update]

好吧,这段代码导致了我的解析错误:

  

无法将符号转换为整数

然后我将其更改为:

after_commit :do_foo_bar, :on => [:create, :update]

我没有错误,但没有任何反应!对日志的进一步调查显示了一个沉默和奇怪的错误:

/home/nuno/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:404: syntax error, unexpected '[', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
...(transaction_include_action?(:[:create, :update]))
...                               ^
/home/nuno/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:412: syntax error, unexpected keyword_end, expecting ')'
/home/nuno/.rvm/gems/ruby-1.9.3-p385/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:413: syntax error, unexpected $end, expecting ')'
Redirected to http://localhost:3000/people/1
Completed 302 Found in 7491ms (ActiveRecord: 410.6ms)

我该如何正确地做到这一点?

1 个答案:

答案 0 :(得分:1)

我认为您使用的Rails版本在回调中不支持此功能。检查下面的功能请求

https://github.com/rails/rails/pull/9356