Skip to content

Instantly share code, notes, and snippets.

@ahk
Created May 7, 2010 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahk/393757 to your computer and use it in GitHub Desktop.
Save ahk/393757 to your computer and use it in GitHub Desktop.
class Grid < ActiveRecord::Base
has_many :rows
has_many :columns
has_many :cells, :through => :rows
accepts_nested_attributes_for :rows,
:allow_destroy => true,
:reject_if => lambda {|a| a[:description].blank? }
accepts_nested_attributes_for :columns,
:allow_destroy => true,
:reject_if => lambda {|a| a[:description].blank? }
end
class Column < ActiveRecord::Base
belongs_to :grid
has_many :cells, :dependent => :destroy
has_many :rows, :through => :grid
end
class Row < ActiveRecord::Base
belongs_to :grid
has_many :cells, :dependent => :destroy
has_many :columns, :through => :grid
accepts_nested_attributes_for :cells
end
class Cell < ActiveRecord::Base
belongs_to :row
belongs_to :column
has_one :grid, :through => :row
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment