<?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>[kumo.it] &#187; plugins</title>
	<atom:link href="http://www.kumo.it/articles/tag/plugins/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kumo.it</link>
	<description></description>
	<lastBuildDate>Wed, 24 Aug 2011 21:38:43 +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>acts_as_confirmable rails plugin</title>
		<link>http://www.kumo.it/articles/2008/06/11/acts_as_confirmable-plugin/</link>
		<comments>http://www.kumo.it/articles/2008/06/11/acts_as_confirmable-plugin/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 08:54:37 +0000</pubDate>
		<dc:creator>kumo</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.kumo.it/?p=83</guid>
		<description><![CDATA[acts_as_confirmable is a Ruby on Rails plugin that is useful when you want to know who ticked a check box and when they did so. It can be found at http://github.com/kumo/acts_as_confirmable/tree/master. This plugin treats a datetime attribute and an integer attribute as a boolean. This boolean can then be used as normal attribute in a [...]]]></description>
			<content:encoded><![CDATA[<p><em>acts_as_confirmable</em> is a Ruby on Rails plugin that is useful when you want to know who ticked a check box and when they did so. It can be found at <a href="http://github.com/kumo/acts_as_confirmable/tree/master">http://github.com/kumo/acts_as_confirmable/tree/master</a>.</p>
<p>This plugin treats a datetime attribute and an integer attribute as a boolean. This boolean can then be used as normal attribute in a check box (or in any part of the program) and when it is checked, the datetime records the moment and the integer records the id of the current user.</p>
<p><em>It is assumed that there is a Users table and that the current user can be found at User.current_user. If the current user cannot be accessed then 1 is used as the id.</em></p>
<p>h3. Installation</p>
<pre lang="bash">
$ cd vendor/plugins
$ git checkout git://github.com/kumo/acts_as_confirmable/tree
</pre>
<p>h3. Usage</p>
<p>* On models where you want to be able to confirm X add a X_confirmed_at datetime and X_confirmed_by integer.<br />
* In the model put acts_as_confirmed :X<br />
* In the views add check boxes (check_box :X)</p>
<p>h3. Example</p>
<p>h4. create a new rails app</p>
<pre lang="bash">
$ rails confirm
$ cd confirm
</pre>
<p>h4. create users table and items table with 3 confirmable fields</p>
<pre lang="bash">
$ script/generate scaffold user name:string
$ script/generate scaffold item name:string \
      started_confirmed_by:integer started_confirmed_at:datetime \
      finished_confirmed_by:integer finished_confirmed_at:datetime \
      ready_confirmed_by:integer ready_confirmed_at:datetime
</pre>
<p>h4. add the plugin to the model</p>
<pre lang="Rails">
class Item < ActiveRecord::Base
  acts_as_confirmable :started, :finished, :ready
end
</pre>
<p>h4. add 3 check boxes in items/new.html.erb and items/edit.html.erb</p>
<pre lang="Rails">


  <%= f.label :started %>
  <%= f.check_box :started %>



  <%= f.label :finished %>
  <%= f.check_box :finished %>



  <%= f.label :ready %>
  <%= f.check_box :ready %>

</pre>
<p>h4. show the confirmation info in items/list.html.erb</p>
<pre lang="Rails">
<td>
  <%=h item.started? %>
  <%=h item.finished_confirmer.name if @item.finished? -%>
</td>
</pre>
<p>h4. example of assigning a user to current_user</p>
<pre lang="Rails">
class User < ActiveRecord::Base
  cattr_accessor :current_user
end

class ItemsController < ApplicationController
  before_filter :load_user

  def load_user
    User.current_user = User.find(:first)
  end
end
</pre>
<p>h3. Available fields</p>
<p>If a model has the attributes fields started_confirmed_at and started_confirmed_by, then the plugin provides:</p>
<p>*
<pre>started?</pre>
<p> -- true if it has been confirmed by someone on a specific date<br />
*
<pre>started</pre>
<p> -- same as above but is normally used by a check box tag<br />
*
<pre>started=</pre>
<p> -- the assignment method that is used by the check box when posting<br />
*
<pre>started_confirmer</pre>
<p> -- the user that confirmed it<br />
*
<pre>started_at</pre>
<p> -- when it was confirmed</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kumo.it/articles/2008/06/11/acts_as_confirmable-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 8/15 queries in 0.028 seconds using disk: basic

Served from: www.kumo.it @ 2012-02-04 21:15:59 -->
