I’m creating action tracking for users in Ruby on Rails 3. And I want to have after_filter method in controllers, but I don’t know how to get current object or current action in my action_tracking method. Any solution?
# some_controller.rb
class SomeController < ApplicationController
after_filter :action_tracking, only: [ :create, :update, :delete ]
...
end
# application_controller.rb
class ApplicationController < ActionController::Base
def action_tracking
action = <get name of action> # create, update or delete...
<object> = <get changed object> # event, user...
changes = <object>.changes # { 'title' => ["Title", "New Title"] }
<object>.tracking.create(action, changes)
end
end
1 Answer