<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>The Bacon Bear Blog: Tag acts_as_flaggable</title>
    <link>http://www.baconbear.com/articles/tag/acts_as_flaggable?tag=acts_as_flaggable</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Acts As Flaggable updated</title>
      <description>&lt;p&gt;Just checked in a small update to Acts As Flaggable that includes the following&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Incorporates suggestion from bitbutter to allow add_flag to take either a Flag object (as before) or a Hash.  If passed a Hash it creates a Flag object from the hash you passed in.&lt;/li&gt;
&lt;li&gt;Added user_has_flagged? instance method to tell you if a user has flagged an object at all or flagged it with a specific flag&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Grab it from &lt;a href="http://svn.baconbear.com/rails_plugins/acts_as_flaggable/trunk/"&gt;trunk&lt;/a&gt; in the normal way!&lt;/p&gt;</description>
      <pubDate>Wed, 06 Dec 2006 13:34:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:cc770546-c79b-4075-b04a-9a00410a84de</guid>
      <author>Jeff</author>
      <link>http://www.baconbear.com/articles/2006/12/06/acts-as-flaggable-updated</link>
      <category>rails</category>
      <category>plugins</category>
      <category>acts_as_flaggable</category>
      <trackback:ping>http://www.baconbear.com/articles/trackback/10</trackback:ping>
    </item>
    <item>
      <title>Acts As Flaggable released</title>
      <description>&lt;p&gt;Here&amp;#8217;s my first stab at a rails plugin, small as it may be.&lt;/p&gt;

&lt;p&gt;Acts As Flaggable is a model modifier which allows flags to be associated with records.  Authors of community driven sites may find this useful for quickly adding the ability to mark records as &amp;#8220;spam&amp;#8221; or &amp;#8220;inappropriate&amp;#8221;.  There&amp;#8217;s also facilities in place to automatically take a specific action automatically if a record has been flagged a certain way too many times (Think auto-removing posts that have been marked as &amp;#8220;spam&amp;#8221;).&lt;/p&gt;

&lt;p&gt;To install:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;script/plugin install http://svn.baconbear.com/rails_plugins/acts_as_flaggable/trunk
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To prepare your database, create a migration with the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def self.up
   create_table :flags, :force =&gt; true do |t|
     t.column :flag, :string, :default =&gt; ""
     t.column :comment, :string, :default =&gt; ""
     t.column :created_at, :datetime, :null =&gt; false
     t.column :flaggable_id, :integer, :default =&gt; 0, :null =&gt; false
     t.column :flaggable_type, :string, :limit =&gt; 15,
       :default =&gt; "", :null =&gt; false
     t.column :user_id, :integer, :default =&gt; 0, :null =&gt; false
   end

   add_index :flags, ["user_id"], :name =&gt; "fk_flags_user"
 end

 def self.down
   drop_table :flags
 end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To prepare your model:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Model &lt; ActiveRecord::Base
    acts_as_flaggable

        protected
        # Flagged method is called after every add_flag.  This callback method
        # is totally optional and does not have to be included in the model
        def flagged(flag, flag_count)
            # Add code here to take action when flag reaches a certain flag_count
        end
 end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To use:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;p = Post.find(someid)
p.add_flag Flag.new(:flag =&gt; :spam, :comment =&gt; 'some comment')
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you notice I used add_flag instead of the typical &amp;lt;&amp;lt; operator allowed by rails.  Currently it&amp;#8217;s a requirement that you use add_flag if you need the flagged callback to be called.  I&amp;#8217;ll probably fix this in a future checkin.&lt;/p&gt;

&lt;p&gt;Avid plugin users will recognize a lot of the code and README from the &lt;a href="http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/"&gt;Acts As Commentable&lt;/a&gt; plugin.  Thanks to the clear and readable manner Acts As Commentable was written in, it was a fairly easy change to morph the commentable plugin into the flaggable plugin I have here.  So, special thanks to Juixe for releasing a well written plugin!&lt;/p&gt;</description>
      <pubDate>Mon, 04 Dec 2006 01:32:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:d58bcfdf-7e21-4239-99d9-91077f547d84</guid>
      <author>Jeff</author>
      <link>http://www.baconbear.com/articles/2006/12/04/acts-as-flaggable-released</link>
      <category>rails</category>
      <category>plugins</category>
      <category>acts_as_flaggable</category>
      <trackback:ping>http://www.baconbear.com/articles/trackback/6</trackback:ping>
    </item>
  </channel>
</rss>
