将参数传递给rails中的after(:create)钩子。这是为什么回调不是很好?

时间:2016-04-05 20:53:28

标签: ruby-on-rails-3

这是我在模型中的代码:

class User
...
  after_create :log_creation!
...

  def log_creation!
    Event.create!(
      :event_type => Event::EventType::USER_ACCOUNT_STARTED,
      :date => Time.now.utc,
      :eventable => self,
      :description => "Automatically populated"
    )
  end
end

我需要在create方法中添加一些东西来处理只在控制器中可用的请求对象。最简单的方法是什么?

这或许是人们不喜欢这些ActiveRecord挂钩的原因吗?它创建了与用户创建有关的任何联系,因此,当它改变这对夫妻行为时......我需要追踪用户被保存的所有地方,这在大型遗留代码中很烦人。这是为什么?

0 个答案:

没有答案