Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Acts as List port for Mongo Mapper
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
lib
model
spec
.DS_Store
README
Rakefile
init.rb

README

This is a (quick and untested) port of classic +acts_as_list+ to Mongo Mapper. It is based on a port by tomasc.

ActsAsList
==========

This acts_as extension provides the capabilities for sorting and reordering a number of objects in a list. If you do not specify custom position +column+ in the options, a key named +position+ will be used automatically.


Example
=======

module DefaultBehavior
  attr_accessor :before_save_triggered

  def log_before_save
    self.before_save_triggered = true
  end
end

class Mixin
  include MongoMapper::Document

  key :pos, Integer
  key :parent_id, Integer
  
  timestamps! # HECK YES   
  
  before_save :log_before_save  
  before_create :add_to_list_bottom #_when_necessary

  def self.table_name 
    "mixins" 
  end

  include DefaultBehavior    
end

# require 'active_model'
require 'acts_as_list/mongo_mapper/rails3'
require 'mixin'

module Config
  def setup_db
    Config.setup_db
  end

  def self.setup_db
    MongoMapper.database = 'acts_as_list_test_db'
  end
end 

Config.setup_db

class TodoList
  include MongoMapper::Document  
  
  has_many :todo_items, :order => "position"
end

class TodoItem < Mixin
  
  include MongoMapper::Document
  include ActsAsList::MongoMapper
  
  key :todo_list_id, ObjectId
  belongs_to :todo_list

  key :name, String

  acts_as_list :scope => :todo_list

end

todo_list = TodoList.new

%w{'clean', 'wash', 'repair'}.each do |name| 
  todo_item = TodoItem.new(:name => name)
  todo_list.todo_items << todo_item
end  

todo_list.todo_items.first.move_to_bottom
todo_list.todo_items.last.move_higher
                     
==

Original acts_as_list Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license
Something went wrong with that request. Please try again.