<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eXpand yOur cReativity &#187; acts_as_audited</title>
	<atom:link href="http://blog.bhushangahire.net/category/rails/acts_as_audited/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bhushangahire.net</link>
	<description></description>
	<lastBuildDate>Thu, 05 Jan 2012 07:17:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Audit site using acts_as_audited plugin</title>
		<link>http://blog.bhushangahire.net/2008/05/17/audit-site-using-acts_as_audited-plugin/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=audit-site-using-acts_as_audited-plugin</link>
		<comments>http://blog.bhushangahire.net/2008/05/17/audit-site-using-acts_as_audited-plugin/#comments</comments>
		<pubDate>Sat, 17 May 2008 06:51:43 +0000</pubDate>
		<dc:creator>Bhushan Ahire</dc:creator>
				<category><![CDATA[acts_as_audited]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.bhushangahire.net/?p=44</guid>
		<description><![CDATA[acts_as_audited is an Active Record plugin that logs all modifications to your models in an audits table. It uses a polymorphic association to store an audit record for any of the model objects that you wish to have audited. The audit log stores the model that the change was on, the “action” (create, update, destroy), [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div>
<code>acts_as_audited</code> is an Active Record plugin that logs all modifications to your models in an <code>audits</code> table. It uses a polymorphic association to store an audit record for any of the model objects that you wish to have audited.  The audit log stores the model that the change was on, the “action” (create, update, destroy), a serialzied hash of the changes, and optionally the user that performed the action.</p>
<h3>Auditing in Rails</h3>
<p><strong><span class="caps">NOTE</span></strong>: read the caveats section if the following isn’t working.</p>
<p>If you’re using acts_as_audited within Rails, you can simply declare which models should be audited.  acts_as_audited can also automatically record the user that made the change if your controller has a <code>current_user</code> method.</p>
<blockquote><p><code class="ruby"><span class="keywords">class</span> <span class="constants">ApplicationController</span> &lt; <span class="constants">ActionController</span>:<span class="symbol">:Base</span></p>
<p>  audit <span class="constants">User</span>, <span class="constants">List</span>, <span class="constants">Item</span><br />
protected<br />
  <span class="keywords">def</span> current_user<br />
    <span class="instance">@user</span> ||= <span class="constants">User</span><span class="method">.find</span><span class="brackets">(</span>session<span class="brackets">[</span><span class="symbol">:user</span><span class="brackets">]</span><span class="brackets">)</span></p>
<p>  <span class="keywords">end</span><br />
<span class="keywords">end</span></code></p></blockquote>
<h3>Caveats</h3>
<p>Auditing with user support depends on Rails’ caching mechanisms, therefore auditing isn’t enabled during development mode. To test that auditing is working, start up your app in production mode, or change the following options in config/environments/development.rb:</p>
<blockquote><p><code class="ruby">config<span class="method">.cache_classes</span> = <span class="constants">true</span></p>
<p>config<span class="method">.action_controller</span><span class="method">.perform_caching</span> = <span class="constants">true</span></code></p></blockquote>
<h3>Customizing</h3>
<p>To get auditing outside of Rails, or to customize which fields are audited within Rails, you can explicitly declare <code>acts_as_audited</code> on your models. The <code>:except</code> option allows you to specify one or more attributes that you don’t want to be saved in the audit log.</p>
<blockquote><p><code class="ruby"><span class="keywords">class</span> <span class="constants">User</span> &lt; <span class="constants">ActiveRecord</span>:<span class="symbol">:Base</span><br />
  acts_as_audited <span class="symbol">:except</span> =&gt; <span class="brackets">[</span><span class="symbol">:password</span>, <span class="symbol">:credit_card_number</span><span class="brackets">]</span></p>
<p><span class="keywords">end</span></code></p></blockquote>
<h3>Installation</h3>
<p>You can grab the plugin by running:</p>
<blockquote><p><code class="ruby">script/plugin install http://source.collectiveidea.com/public/rails/plugins/acts_as_audited</code></p></blockquote>
<p>Run the migration generator and migrate to add the audits table.</p>
<blockquote><p><code class="ruby">script/generate audited_migration add_audits_table<br />
rake db:migrate</code></p></blockquote>
<h3>Upgrading</h3>
<p>Those upgrading from version 0.2 need to add 2 fields the audits table:</p>
<blockquote><p><code class="ruby">add_column :audits, :user_type, :string<br />
add_column :audits, :username, :string</code></p></blockquote>
<p>
May this information fulfills your requirement&#8230; <img src='http://blog.bhushangahire.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />
</div>
<div class="shr-publisher-45"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://blog.bhushangahire.net/2008/05/17/audit-site-using-acts_as_audited-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

