def acts_as_featured(attribute, options = {})
      cattr_accessor :featured_attribute
      cattr_accessor :featured_attribute_scope

      self.featured_attribute = attribute
      self.featured_attribute_scope = options[:scope] || false

      if scope_name = options[:create_scope]
        scope_name = attribute if scope_name == true
        scope scope_name, -> { where(attribute => true).limit(1) }
      end

      before_save :remove_featured_from_other_records
      after_save :add_featured_to_first_record
      before_destroy :add_featured_to_first_record_if_featured
    end
def acts_as_featured(attribute, options = {})
      cattr_accessor :featured_attribute
      cattr_accessor :featured_attribute_scope

      self.featured_attribute = attribute
      self.featured_attribute_scope = options[:scope] || false

      if scope_name = options[:create_scope]
        scope_name = attribute if scope_name == true
        scope scope_name, -> { where(attribute => true).limit(1) }
      end

      before_save :remove_featured_from_other_records
      after_save :add_featured_to_first_record
      before_destroy :add_featured_to_first_record_if_featured
    end
Designates an attribute on this model to indicate "featuredness," where
 only one record within a given scope may be featured at a time.

 Pass in the name of the attribute and an options hash:

 * <tt>:scope</tt> - If given, designates the scope in which this model is featured. This would typically be a <tt>belongs_to</tt> association.
 * <tt>:create_scope</tt> - If <tt>true</tt>, creates a named scope using the name of the attribute given here. If it's a symbol, creates a named scope using that symbol.

    class Project < ActiveRecord::Base
      # no two Projects will ever have their @featured attributes set simultaneously
      acts_as_featured :featured
    end

    class Photo < ActiveRecord::Base
      # each account gets a favorite photo
      belongs_to :account
      acts_as_featured :favorite, :scope => :account
    end

    class Article < ActiveRecord::Base
      # creates a named scope called Article.featured to return the featured article
      acts_as_featured :main, :create_scope => :featured
    end