public
Fork of courtenay/can_flag
Description: flag content as inappropriate
Clone URL: git://github.com/bumi/can_flag.git
Search Repo:
name age message
folder .gitignore Mon Mar 17 01:15:22 -0700 2008 fix associations and callback [courtenay]
folder MIT-LICENSE Sun Mar 16 18:12:01 -0700 2008 steal from acts_as_commentable/acts_as_flaggable [courtenay]
folder README Sun Mar 23 14:20:17 -0700 2008 added callback_with_args method and changed cal... [bumi]
folder Rakefile Sun Mar 16 20:07:24 -0700 2008 start hacking in generators, cargo cult from re... [courtenay]
folder generators/ Mon Mar 17 01:50:17 -0700 2008 enforce reasons when setting [courtenay]
folder init.rb Sun Mar 23 14:20:17 -0700 2008 added callback_with_args method and changed cal... [bumi]
folder install.rb Sun Mar 16 18:35:57 -0700 2008 raping the soul of acts_as_flaggable [courtenay]
folder lib/ Sun Mar 23 14:56:46 -0700 2008 forgot to add the active_record_callbacks file ... [bumi]
folder tasks/ Sun Mar 16 18:12:01 -0700 2008 steal from acts_as_commentable/acts_as_flaggable [courtenay]
folder test/ Mon Mar 17 02:09:24 -0700 2008 link user to flaggings [courtenay]
README
Can Flag
=================

this is a fork that simply changes the way the after_flagged callback works.
after_flagged now gets the Flag object passed instead of the Flaggable object.


Strongly inspired by acts_as_flaggable.
Intended to allow your users to flag content as inappropriate, and set up some ways for you 
to deal with the content.

== Resources

Install

1. Download the tarball from github, or, clone the repository and symlink it into your application.
   Yes, I'm serious.
  
2. $ script/generate can_flag flags

   This will create the following files:
     app/controllers/flags_controller.rb
     spec/helpers/flags_controller_spec.rb
     app/helpers/flags_helper
     db/migrate/flags_migration.rb

3. Modify any content model with
  
   class Article < ActiveRecord::Base
     can_be_flagged
   end
   
   You can also add a callback
   
   class Article
     can_be_flagged
     def after_flagged
       # send an email
       # delete this post
       # suspend the owner of the post if the flags.size > 3
       # suspend the owner of the post if their total flags count > 5
     end
   end

4. Modify your user model with
 
   class User < ActiveRecord::Base
     can_flag     
   end

5. Usage

   article = Article.find(4)
   current_user.flags.create :flaggable => article

 

 * When a flag is added via add_flag, flagged(flag, flag_count) is called
   on the flaggable model.  This allows the model to perform certain
   operations if the number of flags reaches a certain point.  For example,
   you may want to mark a Post as deleted if a Post receives too many "spam"
   flags
 
 * Each flag reference flaggable object
 
 model = Model.find(1)
 model.flags.get(0).commtable == model