Note that there are some explanatory texts on larger screens.

plurals
  1. POKeep a log of user events in rails
    text
    copied!<p>I am currently trying to implement a log for the administration section of my rails application. This will allow an admin to see what actions a user has performed and when. E.g 'User added a new address', 'User updated their postcode from X to Y'.</p> <p>As each action could potentially involve many models, not just the user, I have made a log model which has fields for all the other system models ids, a message and a log code.</p> <pre><code>class CreateLogs &lt; ActiveRecord::Migration def self.up create_table :logs do |t| t.integer :user_id t.integer :marker_id t.integer :administrator_id t.integer :group_id t.integer :assignment_id t.integer :submission_id t.integer :code t.text :message t.timestamps end end def self.down drop_table :logs end end </code></pre> <p>My concern is that for example, a user could (let's say) add an assignment to their account, it gets logged as</p> <pre><code>Log.create(:user_id =&gt; current_user.id, :assignment_id =&gt; the_assignment.id, :code =&gt; 342, :message =&gt; '') </code></pre> <p>(Somewhere the code 342 corresponds to 'User created a new address', hence no need for message)</p> <p>Obviously in a log view, I can pull the relevant user and address info from the log ids/details but if this user or address were to be deleted, all that information would be unavailable and so looking back through the logs, the entry would be basically useless.</p> <p>There has to be a better way or something already out there to help log system events like this and cope with potential deletions.</p> <p>Alternatively I could store the entire entry as a text message but wouldn't that be really bad and fill up the database unnecessarily?</p> <p>Let me know if any of that is unclear, just figured logging application actions/events has to have been done before!</p> <p>Thanks,</p> <p>Pete</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload