Ruby on Rails - 如何在after_filter中获取更改的对象?

时间:2011-11-18 15:43:00

标签: ruby-on-rails filter ruby-on-rails-3.1

我正在为Ruby on Rails 3中的用户创建动作跟踪。我想在控制器中使用after_filter方法,但我不知道如何在我的{{1}中获取当前对象或当前动作}} 方法。任何解决方案?

action_tracking

1 个答案:

答案 0 :(得分:0)

def action_tracking
  action = params[:action]
  changes = changed_object.changes
  changed_object.tracking.create(action, changes)
end

# override for each controller
# there is no way to know this in a generic way, unless you use something
# like inherited_resources, or active scaffold, where the objects is "known"
def changed_object
  @user
end