```ruby
class ActionLog < ActiveRecord::Base
  serialize :data

  def self.log action, source, sender = nil, ip = nil, data = {}, admin_id = nil
    create! action: action, source: source, sender_id: sender.try(:id), sender_type: sender.try(:class).try(:name), ip: ip, data: data, admin_id: (admin_id.present? && admin_id.respond_to?(:id) ? admin_id.id : admin_id)
  end
end
```

Use ActiveRecord polymorphism to set sender
user
```ruby
class ActionLog < ActiveRecord::Base
  belongs_to :sender, polymorphic: true
  serialize :data

  def self.log action, source, sender = nil, ip = nil, data = {}, admin_id = nil
    create! action: action, source: source, sender: sender, ip: ip, data: data, admin_id: (admin_id.present? && admin_id.respond_to?(:id) ? admin_id.id : admin_id)
  end
end
```
assistant