Creating a dashboard in Rails

Say I had an application that was an address book. I would like to have a dashboard page. On this page, I would like to run a list of events that occur in the application itself.

Examples of events may include:

  • User adds contact.
  • The user deletes the contact.
  • The user updates the contact.

What would be the best way to create this type of functionality? Initially, I felt that I could make some creative database calls with existing data, but I could not handle events that delete data, for example, when a contact is deleted.

So, now I think that it should be a separate table that simply stored events as they occurred. Will it be like most sites do?

I could go through my entire application, and every time a CRUD operation is performed, I could create a new element in a table that describes in detail what happened, but it does not look very dry.

I assumed that my question would be - the best way to create toolbar functionality in an existing application such as an address book?

Everyone is welcome any guide.

+5
source share
5 answers

The easiest way to do this is with the Observers user in addition to the "logger" table in your database.

Logger
  id
  model_name
  model_id
  message

This way you can configure Observer for all the models you want to register, and do something like this:

after_delete(contact)
  Logger.create({:model_name => contact.class.to_s,
                 :model_id => contact.id,
                 :message => "Contact was deleted at #{Time.now}"})
end

, . " ", , , , . , acts_as_paranoid.

, , - , , ( , ).

+6

Timeline Fu: http://github.com/jamesgolick/timeline_fu:

class Post < ActiveRecord::Base
  belongs_to :author, :class_name => 'Person'
  fires :new_post, :on    => :create,
                 :actor => :author
end
+2

.

, .

quick link, .

+1
+1

paper_trail, !. , .

0

All Articles