4. • position integer
• model acts_as_list
class CreateUsers < ActiveRecord::Migration class User < ActiveRecord::Base
def self.up acts_as_list
create_table :users do |t| validates_presence_of :name
t.column :name, :string end
t.column :position, :integer
end
end
def self.down
drop_table :users
end
end
6. position
• acts_as_list :scope=>XXX
class CreateMobileSuits < class MobileSuit < ActiveRecord::Base
ActiveRecord::Migration belongs_to :group
def self.up acts_as_list :scope => :group
create_table :mobile_suits do |t| end
t.column :group_id,:integer
t.column :position,:integer
t.column :name, :string
end
end
def self.down
drop_table :mobile_suits
end
end
9. • parent_id integer
• model acts_as_tree
class CreateDepartments < ActiveRecord::Migration class Department < ActiveRecord::Base
def self.up acts_as_tree :order => :id
create_table :departments do |t| end
t.column :name, :string
t.column :parent_id, :integer
end
end
def self.down
drop_table :departments
end
end
14. • parent_id,lft,rgt integer
• model acts_as_nested_set
class CreateOrganizations < ActiveRecord::Migration class Organization < ActiveRecord::Base
def self.up acts_as_nested_set
create_table :organizations do |t| end
t.column :name, :string
t.column :parent_id, :integer
t.column :lft, :integer
t.column :rgt, :integer
end
end
def self.down
drop_table :organizations
end
end